Skip to content

Commit d71e985

Browse files
Merge pull request #230 from CSSLab/claude/reduce-vercel-costs-oyBK8
remove active-users endpoint to reduce Vercel costs
2 parents ec2291b + 2b0c2ad commit d71e985

3 files changed

Lines changed: 8 additions & 169 deletions

File tree

src/api/home.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
import { buildUrl } from './utils'
22

3-
export const getActiveUserCount = async (): Promise<number> => {
4-
try {
5-
const response = await fetch('/api/active-users')
6-
7-
const data = await response.json()
8-
9-
if (data.success && typeof data.activeUsers === 'number') {
10-
return data.activeUsers
11-
}
12-
} catch (error) {
13-
console.error('Failed to fetch active user count:', error)
14-
}
15-
16-
return 0
17-
}
18-
193
export const getGlobalStats = async () => {
204
const res = await fetch(buildUrl('auth/global_stats'))
215
const data = await res.json()

src/components/Home/HomeHero.tsx

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from 'src/lib/analytics'
88

99
import { PlayType } from 'src/types'
10-
import { getGlobalStats, getActiveUserCount } from 'src/api'
10+
import { getGlobalStats } from 'src/api'
1111
import { AuthContext, ModalContext } from 'src/contexts'
1212
import { AnimatedNumber } from 'src/components/Common/AnimatedNumber'
1313

@@ -112,7 +112,6 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
112112
puzzle_games_total: number
113113
turing_games_total: number
114114
}>()
115-
const [activeUsers, setActiveUsers] = useState<number>(0)
116115
const { setPlaySetupModalProps } = useContext(ModalContext)
117116
const { user, connectLichess } = useContext(AuthContext)
118117

@@ -139,22 +138,6 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
139138
return () => clearInterval(interval)
140139
}, [])
141140

142-
// Fetch active users count and set up periodic updates
143-
useEffect(() => {
144-
const fetchActiveUsers = async () => {
145-
const count = await getActiveUserCount()
146-
setActiveUsers(count)
147-
}
148-
149-
// Fetch immediately
150-
fetchActiveUsers()
151-
152-
// Update every 5 minutes
153-
const interval = setInterval(fetchActiveUsers, 5 * 60 * 1000)
154-
155-
return () => clearInterval(interval)
156-
}, [])
157-
158141
return (
159142
<Fragment>
160143
<BetaBlurb />
@@ -263,15 +246,6 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
263246
</div>
264247
</div>
265248
<motion.div className="flex flex-wrap justify-center gap-6 px-2">
266-
{activeUsers > 0 && (
267-
<p className="text-center text-base text-white/80">
268-
<AnimatedNumber
269-
value={activeUsers}
270-
className="font-bold text-white"
271-
/>{' '}
272-
recent users
273-
</p>
274-
)}
275249
<p className="text-center text-base text-white/80">
276250
<AnimatedNumber
277251
value={globalStats?.play_moves_total || 0}
@@ -286,15 +260,13 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
286260
/>{' '}
287261
puzzles solved
288262
</p>
289-
{activeUsers <= 0 && (
290-
<p className="text-center text-base text-white/80">
291-
<AnimatedNumber
292-
value={globalStats?.turing_games_total || 0}
293-
className="font-bold text-white"
294-
/>{' '}
295-
turing games played
296-
</p>
297-
)}
263+
<p className="text-center text-base text-white/80">
264+
<AnimatedNumber
265+
value={globalStats?.turing_games_total || 0}
266+
className="font-bold text-white"
267+
/>{' '}
268+
turing games played
269+
</p>
298270
</motion.div>
299271
</div>
300272
</Fragment>

src/pages/api/active-users.ts

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)