From 969bc1fcbaa14a64537eb4246d48021fa332e95a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 25 Jul 2023 17:49:42 -0500 Subject: [PATCH] TrendsDB: cleanup on construction --- src/trends.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/trends.ts b/src/trends.ts index 2c28396..9a04fa1 100644 --- a/src/trends.ts +++ b/src/trends.ts @@ -18,11 +18,14 @@ class TrendsDB { CREATE INDEX IF NOT EXISTS idx_time_tag ON tag_usages(inserted_at, tag); `); - setInterval(() => { + const cleanup = () => { console.info('Cleaning up old tag usages...'); const lastWeek = new Date(new Date().getTime() - Time.days(7)); this.cleanupTagUsages(lastWeek); - }, Time.days(1)); + }; + + setInterval(cleanup, Time.hours(1)); + cleanup(); } getTrendingTags(since: Date, until: Date, limit = 10) {