TrendsDB: cleanup on construction

This commit is contained in:
Alex Gleason 2023-07-25 17:49:42 -05:00
parent cbb294dbc2
commit 969bc1fcba
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 5 additions and 2 deletions

View File

@ -18,11 +18,14 @@ class TrendsDB {
CREATE INDEX IF NOT EXISTS idx_time_tag ON tag_usages(inserted_at, tag); CREATE INDEX IF NOT EXISTS idx_time_tag ON tag_usages(inserted_at, tag);
`); `);
setInterval(() => { const cleanup = () => {
console.info('Cleaning up old tag usages...'); console.info('Cleaning up old tag usages...');
const lastWeek = new Date(new Date().getTime() - Time.days(7)); const lastWeek = new Date(new Date().getTime() - Time.days(7));
this.cleanupTagUsages(lastWeek); this.cleanupTagUsages(lastWeek);
}, Time.days(1)); };
setInterval(cleanup, Time.hours(1));
cleanup();
} }
getTrendingTags(since: Date, until: Date, limit = 10) { getTrendingTags(since: Date, until: Date, limit = 10) {