Trends: add limit param, fix order

This commit is contained in:
Alex Gleason 2023-07-25 20:40:31 -05:00
parent 1a860adde7
commit ad48e4a787
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 4 additions and 3 deletions

View File

@ -54,16 +54,17 @@ class TrendsDB {
})); }));
} }
getTagHistory(tag: string, since: Date, until: Date) { getTagHistory(tag: string, since: Date, until: Date, limit = 7) {
return this.#db.query<string[]>( return this.#db.query<string[]>(
` `
SELECT inserted_at, COUNT(DISTINCT pubkey8), COUNT(*) SELECT inserted_at, COUNT(DISTINCT pubkey8), COUNT(*)
FROM tag_usages FROM tag_usages
WHERE tag = ? AND inserted_at >= ? AND inserted_at < ? WHERE tag = ? AND inserted_at >= ? AND inserted_at < ?
GROUP BY date(inserted_at) GROUP BY date(inserted_at)
ORDER BY date(inserted_at); ORDER BY date(inserted_at) DESC
LIMIT ?;
`, `,
[tag, since, until], [tag, since, until, limit],
).map((row) => ({ ).map((row) => ({
day: new Date(row[0]), day: new Date(row[0]),
accounts: Number(row[1]), accounts: Number(row[1]),