diff --git a/src/controllers/api/trends.ts b/src/controllers/api/trends.ts index f88b486..d4a4f7e 100644 --- a/src/controllers/api/trends.ts +++ b/src/controllers/api/trends.ts @@ -4,17 +4,17 @@ import { trends } from '@/trends.ts'; import { Time } from '@/utils.ts'; const trendingTagsController: AppController = (c) => { - const yesterday = new Date(new Date().getTime() - Time.days(1)); const now = new Date(); + const yesterday = new Date(now.getTime() - Time.days(1)); const tags = trends.getTrendingTags(yesterday, now); - return c.json(tags.map(({ name, accounts }) => ({ + return c.json(tags.map(({ name, accounts, uses }) => ({ name, url: Conf.local(`/tags/${name}`), history: [{ day: String(Math.floor(yesterday.getTime() / 1000)), - uses: String(accounts), // Not actually true - we don't collect this + uses: String(uses), accounts: String(accounts), }], }))); diff --git a/src/trends.ts b/src/trends.ts index 4831168..e112673 100644 --- a/src/trends.ts +++ b/src/trends.ts @@ -21,7 +21,7 @@ class TrendsDB { getTrendingTags(since: Date, until: Date) { return this.#db.query( ` - SELECT tag, COUNT(DISTINCT pubkey8) + SELECT tag, COUNT(DISTINCT pubkey8), COUNT(*) FROM tag_usages WHERE inserted_at >= ? AND inserted_at < ? GROUP BY tag @@ -32,6 +32,7 @@ class TrendsDB { ).map((row) => ({ name: row[0], accounts: Number(row[1]), + uses: Number(row[2]), })); }