From 88fd742577297eee9777ffbca75161eabdf714ef Mon Sep 17 00:00:00 2001 From: bountyCoder Date: Wed, 8 Feb 2023 11:08:28 +0000 Subject: [PATCH 1/3] updated the code to check for the --- src/services/GroupService.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/services/GroupService.js b/src/services/GroupService.js index 87f4a0d..5b239bb 100644 --- a/src/services/GroupService.js +++ b/src/services/GroupService.js @@ -192,10 +192,10 @@ async function createGroup(currentUser, data) { await helper.postBusEvent(config.KAFKA_GROUP_CREATE_TOPIC, group) await tx.commit() - // set the cache - const cache = await helper.getCacheInstance() - cache.set(group.id, group) - cache.set(`${group.id}-members`, []) + // do not set the cache as while creating the groups is not having the `oldId` + // const cache = await helper.getCacheInstance() + // cache.set(group.id, group) + // cache.set(`${group.id}-members`, []) return group } catch (error) { @@ -275,9 +275,9 @@ async function updateGroup(currentUser, groupId, data) { await helper.postBusEvent(config.KAFKA_GROUP_UPDATE_TOPIC, updatedGroup) await tx.commit() - // update the cache + // update the cache only if the group has the `oldId` const cache = await helper.getCacheInstance() - cache.set(group.id, updatedGroup) + if (updateGroup.oldId.length > 0) cache.set(group.id, updatedGroup) return updatedGroup } catch (error) { @@ -425,7 +425,7 @@ async function getGroup(currentUser, groupId, criteria) { ) } } - + let session const getSession = () => { if (!session) { @@ -459,7 +459,9 @@ async function getGroup(currentUser, groupId, criteria) { } } else { groupToReturn = await helper.ensureExists(getSession(), 'Group', groupId, isAdmin) - cache.set(groupId, groupToReturn) + + // set the group in cache only if it is having the `oldId` + if (groupToReturn.oldId.length > 0) cache.set(groupId, groupToReturn) if (!isAdmin) delete groupToReturn.status @@ -504,7 +506,9 @@ async function getGroup(currentUser, groupId, criteria) { }) groupToReturn.flattenGroupIdTree = flattenGroupIdTree - cache.set(groupId, groupToReturn) + + // set the group in cache only if it is having the `oldId` + if (groupToReturn.oldId.length > 0) cache.set(groupId, groupToReturn) } } else if (criteria.includeParentGroup && !groupToReturn.parentGroups) { // find parent groups From 83cee4f4aa86574e3be4baf898f03680cbda2abd Mon Sep 17 00:00:00 2001 From: bountyCoder Date: Wed, 8 Feb 2023 11:31:07 +0000 Subject: [PATCH 2/3] updated the condition to check the existance of the field --- src/services/GroupService.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/GroupService.js b/src/services/GroupService.js index 5b239bb..8d6cc49 100644 --- a/src/services/GroupService.js +++ b/src/services/GroupService.js @@ -277,7 +277,7 @@ async function updateGroup(currentUser, groupId, data) { // update the cache only if the group has the `oldId` const cache = await helper.getCacheInstance() - if (updateGroup.oldId.length > 0) cache.set(group.id, updatedGroup) + if (updateGroup.oldId && updateGroup.oldId.length > 0) cache.set(group.id, updatedGroup) return updatedGroup } catch (error) { @@ -461,7 +461,7 @@ async function getGroup(currentUser, groupId, criteria) { groupToReturn = await helper.ensureExists(getSession(), 'Group', groupId, isAdmin) // set the group in cache only if it is having the `oldId` - if (groupToReturn.oldId.length > 0) cache.set(groupId, groupToReturn) + if (groupToReturn.oldId && groupToReturn.oldId.length > 0) cache.set(groupId, groupToReturn) if (!isAdmin) delete groupToReturn.status @@ -508,7 +508,7 @@ async function getGroup(currentUser, groupId, criteria) { groupToReturn.flattenGroupIdTree = flattenGroupIdTree // set the group in cache only if it is having the `oldId` - if (groupToReturn.oldId.length > 0) cache.set(groupId, groupToReturn) + if (groupToReturn.oldId && groupToReturn.oldId.length > 0) cache.set(groupId, groupToReturn) } } else if (criteria.includeParentGroup && !groupToReturn.parentGroups) { // find parent groups From 5a2f199e2f9d0194dad5aec52ca8a3cffd988f5a Mon Sep 17 00:00:00 2001 From: bountyCoder Date: Wed, 8 Feb 2023 11:36:26 +0000 Subject: [PATCH 3/3] removed the caching implementation for the createGroup --- src/services/GroupService.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/services/GroupService.js b/src/services/GroupService.js index 8d6cc49..bd2b1eb 100644 --- a/src/services/GroupService.js +++ b/src/services/GroupService.js @@ -192,11 +192,6 @@ async function createGroup(currentUser, data) { await helper.postBusEvent(config.KAFKA_GROUP_CREATE_TOPIC, group) await tx.commit() - // do not set the cache as while creating the groups is not having the `oldId` - // const cache = await helper.getCacheInstance() - // cache.set(group.id, group) - // cache.set(`${group.id}-members`, []) - return group } catch (error) { logger.error(error)