From: xangelo Date: Sat, 27 Jan 2024 03:59:05 +0000 (-0500) Subject: fix: only query feeds that havent been queried in the last 5 miuntes X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=d39e1b0c20a572a0b670edae6d21c291f03038b2;p=river.git fix: only query feeds that havent been queried in the last 5 miuntes --- 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(); });