Skip to content

Commit

Permalink
Merge pull request #141 from topcoder-platform/develop
Browse files Browse the repository at this point in the history
skip caching if `oldId` is not present
  • Loading branch information
ThomasKranitsas authored Feb 8, 2023
2 parents c260ba9 + af6763b commit e7c46ad
Showing 1 changed file with 9 additions and 10 deletions.
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

0 comments on commit e7c46ad

Please sign in to comment.