Trends: also track total tag usages

This commit is contained in:
Alex Gleason 2023-07-25 17:19:31 -05:00
parent 1d67181e52
commit e8df411834
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 5 additions and 4 deletions

View File

@ -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),
}],
})));

View File

@ -21,7 +21,7 @@ class TrendsDB {
getTrendingTags(since: Date, until: Date) {
return this.#db.query<string[]>(
`
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]),
}));
}