Trends: clean up old tag usages

This commit is contained in:
Alex Gleason 2023-07-25 17:33:16 -05:00
parent e8df411834
commit 48b7310d52
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 7 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import { Sqlite } from '@/deps.ts';
import { hashtagSchema, hexIdSchema } from '@/schema.ts';
import { Time } from './utils.ts';
class TrendsDB {
#db: Sqlite;
@ -16,6 +17,12 @@ class TrendsDB {
CREATE INDEX IF NOT EXISTS idx_time_tag ON tag_usages(inserted_at, tag);
`);
setInterval(() => {
console.info('Cleaning up old tag usages...');
const lastWeek = new Date(new Date().getTime() - Time.days(7));
this.cleanupTagUsages(lastWeek);
}, Time.days(1));
}
getTrendingTags(since: Date, until: Date) {