From 6a53ccf814adfbb894551c7a74866c7fc34a0182 Mon Sep 17 00:00:00 2001 From: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com> Date: Fri, 5 Jul 2019 08:43:56 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=8F=E3=83=83=E3=82=B7=E3=83=A5=E3=82=BF?= =?UTF-8?q?=E3=82=B0=E3=81=AE=E3=83=88=E3=83=AC=E3=83=B3=E3=83=89=E3=81=AE?= =?UTF-8?q?=E8=A8=88=E7=AE=97=E3=82=925=E5=88=86=E5=8D=98=E4=BD=8D?= =?UTF-8?q?=E3=81=A7=E4=B8=B8=E3=82=81=E3=82=8B=20(#5107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/api/endpoints/hashtags/trend.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/server/api/endpoints/hashtags/trend.ts b/src/server/api/endpoints/hashtags/trend.ts index 3154461e5a..a004732f81 100644 --- a/src/server/api/endpoints/hashtags/trend.ts +++ b/src/server/api/endpoints/hashtags/trend.ts @@ -54,8 +54,11 @@ export default define(meta, async () => { const instance = await fetchMeta(true); const hiddenTags = instance.hiddenTags.map(t => t.toLowerCase()); + const now = new Date(); // 5分単位で丸めた現在日時 + now.setMinutes(Math.round(now.getMinutes() / 5) * 5, 0, 0); + const tagNotes = await Notes.createQueryBuilder('note') - .where(`note.createdAt > :date`, { date: new Date(Date.now() - rangeA) }) + .where(`note.createdAt > :date`, { date: new Date(now.getTime() - rangeA) }) .andWhere(`note.tags != '{}'`) .select(['note.tags', 'note.userId']) .cache(60000) // 1 min @@ -106,8 +109,8 @@ export default define(meta, async () => { countPromises.push(Promise.all(hots.map(tag => Notes.createQueryBuilder('note') .select('count(distinct note.userId)') .where(':tag = ANY(note.tags)', { tag: tag }) - .andWhere('note.createdAt < :lt', { lt: new Date(Date.now() - (interval * i)) }) - .andWhere('note.createdAt > :gt', { gt: new Date(Date.now() - (interval * (i + 1))) }) + .andWhere('note.createdAt < :lt', { lt: new Date(now.getTime() - (interval * i)) }) + .andWhere('note.createdAt > :gt', { gt: new Date(now.getTime() - (interval * (i + 1))) }) .cache(60000) // 1 min .getRawOne() .then(x => parseInt(x.count, 10)) @@ -119,7 +122,7 @@ export default define(meta, async () => { const totalCounts = await Promise.all(hots.map(tag => Notes.createQueryBuilder('note') .select('count(distinct note.userId)') .where(':tag = ANY(note.tags)', { tag: tag }) - .andWhere('note.createdAt > :gt', { gt: new Date(Date.now() - (interval * range)) }) + .andWhere('note.createdAt > :gt', { gt: new Date(now.getTime() - (interval * range)) }) .cache(60000) // 1 min .getRawOne() .then(x => parseInt(x.count, 10))