From 48b7310d52727a5f29c63a290a4f193909926516 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 25 Jul 2023 17:33:16 -0500 Subject: [PATCH] Trends: clean up old tag usages --- src/trends.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/trends.ts b/src/trends.ts index e112673..86a2873 100644 --- a/src/trends.ts +++ b/src/trends.ts @@ -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) {