Trends: also track total tag usages
This commit is contained in:
parent
1d67181e52
commit
e8df411834
|
@ -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),
|
||||
}],
|
||||
})));
|
||||
|
|
|
@ -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]),
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue