Skip to content

Commit

Permalink
Merge pull request #361 from bountyC0d3r/develop
Browse files Browse the repository at this point in the history
changes for the oldId
  • Loading branch information
luizrrodrigues authored Mar 6, 2023
2 parents fd71be9 + 9730888 commit 38a21db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- attach_workspace:
at: .
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run: npm publish
- run: npm publish --tag test-release
# dont change anything
workflows:
version: 2
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
"test": "npm run lint && npm run jest"
},
"version": "1.2.10",
"version": "1000.29.16",
"dependencies": {
"auth0-js": "^6.8.4",
"config": "^3.2.0",
Expand Down
29 changes: 10 additions & 19 deletions src/services/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,28 +319,19 @@ class GroupService {
* cache. Defaults to 5 minutes.
* @return {Promise} Resolves to ID array.
*/
async getGroupTreeIds(rootGroupId, maxage = 5 * 60 * 1000) {
const now = Date.now();
const cache = this.private.cache.groupTreeIds;
async getGroupTreeIds(rootGroupId) {
const rootGroupURL = `/groups/${rootGroupId}`;
const rootGroupRes = await this.private.api.get(rootGroupURL);
const rootGroupJSON = await handleApiResponse(rootGroupRes);

/* 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 url = `/groups/${rootGroupJSON.id}?flattenGroupIdTree=true`;
const response = await this.private.api.get(url);
const responseJSON = await handleApiResponse(response);

/* 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 treeIds = responseJSON.flattenGroupIdTree;
treeIds.push(responseJSON.id);

/* 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 };
return _.clone(res);
return treeIds;
}

/**
Expand Down

0 comments on commit 38a21db

Please sign in to comment.