From d39e1b0c20a572a0b670edae6d21c291f03038b2 Mon Sep 17 00:00:00 2001 From: xangelo Date: Fri, 26 Jan 2024 22:59:05 -0500 Subject: [PATCH] fix: only query feeds that havent been queried in the last 5 miuntes --- src/server.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/server.ts b/src/server.ts index 83f1244..06c1b62 100644 --- a/src/server.ts +++ b/src/server.ts @@ -16,6 +16,8 @@ const db = knex({ const parser = new Parser(); const app = express(); +const FEED_REFRESH_RATE = parseInt(process.env.FEED_REFRESH_RATE || '0'); + function contentExtractor(feed: FeedSchema, item): string { let str = ''; switch(feed.title) { @@ -41,7 +43,7 @@ async function queryFeeds() { const feedsToQuery = completeFeedList.filter(feed => { // only update every 5 minutes - return Date.now() > (feed.updated_at + (1000 * 60 * 5)); + return Math.floor(Date.now()/1000) > (feed.updated_at + (1000 * 60 * FEED_REFRESH_RATE)); }); console.log(`Querying ${feedsToQuery.length} feeds`); @@ -89,7 +91,10 @@ async function queryFeeds() { } } - setTimeout(queryFeeds, (Number(process.env.FEED_REFRESH_RATE) + 1) * 1000 * 60); + // we query every minute, incase new feeds were added + // but we only check feeds that havne't been checked + // in the last 5 minutes (based on FEED_REFRESH_RATE) + setTimeout(queryFeeds, 1000 * 60); } app.use(express.static(join(__dirname, 'public'))); @@ -196,7 +201,7 @@ app.delete('/feeds/:feed_id', async (req, res) => { app.listen(process.env.API_PORT, () => { console.log(`Listening on port ${process.env.API_PORT}`); - console.log(`Feed refresh rate: ${(Number(process.env.FEED_REFRESH_RATE) + 1)}m`); + console.log(`Feed refresh rate: ${FEED_REFRESH_RATE}m`); queryFeeds(); }); -- 2.25.1