From 20288325bbc0ba54a872f916c9b0777df7637bc9 Mon Sep 17 00:00:00 2001 From: Bounty Coder Date: Mon, 5 Dec 2022 15:25:18 +0000 Subject: [PATCH 1/2] increased cache refresh duration --- src/services/groups.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/services/groups.js b/src/services/groups.js index 1a672a9..da5dd50 100644 --- a/src/services/groups.js +++ b/src/services/groups.js @@ -320,32 +320,26 @@ class GroupService { * @return {Promise} Resolves to ID array. */ async getGroupTreeIds(rootGroupId, maxage = 5 * 60 * 1000) { - //TODO: Once the fix is validated and working, remove all commented code related to caching - /** - * Removing the caching mechanism, - * as the group created on the day will only be pickedup on the next day - * and stored in the cache - */ - // const now = Date.now(); - // const cache = this.private.cache.groupTreeIds; + const now = Date.now(); + const cache = this.private.cache.groupTreeIds; /* Clean-up: removes stale records from the cache. */ - // const CLEAN_UP_INTERVAL = 24 * 60 * 60 * 1000; // 1 day in ms. - // if (now - cache.lastCleanUp > CLEAN_UP_INTERVAL) { - // _.forOwn(cache, ({ timestamp }, key) => { - // if (now - timestamp > CLEAN_UP_INTERVAL) delete cache[key]; - // }); - // cache.lastCleanUp = now; - // } + const CLEAN_UP_INTERVAL = 1 * 60 * 60 * 1000; // 1 hour in ms. + if (now - cache.lastCleanUp > CLEAN_UP_INTERVAL) { + _.forOwn(cache, ({ timestamp }, key) => { + if (now - timestamp > CLEAN_UP_INTERVAL) delete cache[key]; + }); + cache.lastCleanUp = now; + } /* If result is found in cache, and is fresh enough, return it. */ - // const cached = cache[rootGroupId]; - // if (cached && now - cached.timestamp < maxage) return _.clone(cached.data); + const cached = cache[rootGroupId]; + if (cached && now - cached.timestamp < maxage) return _.clone(cached.data); /* Otherwise, fetch result from the API, write it to the cache, and * finally return that. */ const res = reduceGroupIds(await this.getGroup(rootGroupId)); - // cache[rootGroupId] = { data: res, timestamp: now }; + cache[rootGroupId] = { data: res, timestamp: now }; return _.clone(res); } From 95aa1e78c654d610407d793ee5f23f5d937d6a29 Mon Sep 17 00:00:00 2001 From: Bounty Coder Date: Mon, 5 Dec 2022 16:03:13 +0000 Subject: [PATCH 2/2] fixed the lint issue --- src/services/groups.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/groups.js b/src/services/groups.js index da5dd50..01ca9e5 100644 --- a/src/services/groups.js +++ b/src/services/groups.js @@ -409,4 +409,4 @@ export function getService(tokenV3) { return lastInstance; } -export default undefined; \ No newline at end of file +export default undefined; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy