From 68571d8f577e0a9eb8679e8dd30e11d8b1709340 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 17 Apr 2021 15:30:26 +0900 Subject: Implement user online status Resolve #7422 Fix #7424 --- src/server/api/endpoints/get-online-users-count.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/server/api/endpoints/get-online-users-count.ts') diff --git a/src/server/api/endpoints/get-online-users-count.ts b/src/server/api/endpoints/get-online-users-count.ts index 150ac9e365..a13363055f 100644 --- a/src/server/api/endpoints/get-online-users-count.ts +++ b/src/server/api/endpoints/get-online-users-count.ts @@ -1,6 +1,7 @@ +import { USER_ONLINE_THRESHOLD } from '@/const'; +import { Users } from '@/models'; +import { MoreThan } from 'typeorm'; import define from '../define'; -import { redisClient } from '../../../db/redis'; -import config from '@/config'; export const meta = { tags: ['meta'], @@ -11,12 +12,12 @@ export const meta = { } }; -export default define(meta, (ps, user) => { - return new Promise((res, rej) => { - redisClient.pubsub('numsub', config.host, (_, x) => { - res({ - count: x[1] - }); - }); +export default define(meta, async () => { + const count = await Users.count({ + lastActiveDate: MoreThan(new Date(Date.now() - USER_ONLINE_THRESHOLD)) }); + + return { + count + }; }); -- cgit v1.2.3-freya