diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-06-11 11:24:29 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-06-11 11:24:29 +0900 |
| commit | 7d7193cb63ac8811152707a6896e5cf7ae05258c (patch) | |
| tree | 7f17252e199ad4f77f7ce5a39fb8e0ad85ea343c /src/server/api/endpoints | |
| parent | wip (diff) | |
| download | sharkey-7d7193cb63ac8811152707a6896e5cf7ae05258c.tar.gz sharkey-7d7193cb63ac8811152707a6896e5cf7ae05258c.tar.bz2 sharkey-7d7193cb63ac8811152707a6896e5cf7ae05258c.zip | |
:v:
Diffstat (limited to 'src/server/api/endpoints')
| -rw-r--r-- | src/server/api/endpoints/hashtags/trend.ts | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/server/api/endpoints/hashtags/trend.ts b/src/server/api/endpoints/hashtags/trend.ts index 3b95e1fa4c..6a49fec3d8 100644 --- a/src/server/api/endpoints/hashtags/trend.ts +++ b/src/server/api/endpoints/hashtags/trend.ts @@ -4,13 +4,10 @@ import Note from '../../../../models/note'; * Get trends of hashtags */ module.exports = (params, user) => new Promise(async (res, rej) => { - // 10分 - const interval = 1000 * 60 * 10; - const data = await Note.aggregate([{ $match: { createdAt: { - $gt: new Date(Date.now() - interval) + $gt: new Date(Date.now() - 1000 * 60 * 60) }, tags: { $exists: true, @@ -48,6 +45,10 @@ module.exports = (params, user) => new Promise(async (res, rej) => { }> }>; + if (data.length == 0) { + return res([]); + } + const hots = data[0].tags .sort((a, b) => a.count - b.count) .map(tag => tag.tag) @@ -56,6 +57,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { const countPromises: Array<Promise<number[]>> = []; for (let i = 0; i < 10; i++) { + // 10分 + const interval = 1000 * 60 * 10; + countPromises.push(Promise.all(hots.map(tag => Note.count({ tags: tag, createdAt: { |