Skip to content

skip caching if oldId is not present #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/services/GroupService.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,6 @@ 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`, [])

return group
} catch (error) {
logger.error(error)
Expand Down Expand Up @@ -275,9 +270,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 && updateGroup.oldId.length > 0) cache.set(group.id, updatedGroup)

return updatedGroup
} catch (error) {
Expand Down Expand Up @@ -425,7 +420,7 @@ async function getGroup(currentUser, groupId, criteria) {
)
}
}

let session
const getSession = () => {
if (!session) {
Expand Down Expand Up @@ -459,7 +454,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 && groupToReturn.oldId.length > 0) cache.set(groupId, groupToReturn)

if (!isAdmin) delete groupToReturn.status

Expand Down Expand Up @@ -504,7 +501,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 && groupToReturn.oldId.length > 0) cache.set(groupId, groupToReturn)
}
} else if (criteria.includeParentGroup && !groupToReturn.parentGroups) {
// find parent groups
Expand Down