Skip to content

Commit e7c46ad

Browse files
Merge pull request #141 from topcoder-platform/develop
skip caching if `oldId` is not present
2 parents c260ba9 + af6763b commit e7c46ad

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/services/GroupService.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,6 @@ async function createGroup(currentUser, data) {
192192
await helper.postBusEvent(config.KAFKA_GROUP_CREATE_TOPIC, group)
193193
await tx.commit()
194194

195-
// set the cache
196-
const cache = await helper.getCacheInstance()
197-
cache.set(group.id, group)
198-
cache.set(`${group.id}-members`, [])
199-
200195
return group
201196
} catch (error) {
202197
logger.error(error)
@@ -275,9 +270,9 @@ async function updateGroup(currentUser, groupId, data) {
275270
await helper.postBusEvent(config.KAFKA_GROUP_UPDATE_TOPIC, updatedGroup)
276271
await tx.commit()
277272

278-
// update the cache
273+
// update the cache only if the group has the `oldId`
279274
const cache = await helper.getCacheInstance()
280-
cache.set(group.id, updatedGroup)
275+
if (updateGroup.oldId && updateGroup.oldId.length > 0) cache.set(group.id, updatedGroup)
281276

282277
return updatedGroup
283278
} catch (error) {
@@ -425,7 +420,7 @@ async function getGroup(currentUser, groupId, criteria) {
425420
)
426421
}
427422
}
428-
423+
429424
let session
430425
const getSession = () => {
431426
if (!session) {
@@ -459,7 +454,9 @@ async function getGroup(currentUser, groupId, criteria) {
459454
}
460455
} else {
461456
groupToReturn = await helper.ensureExists(getSession(), 'Group', groupId, isAdmin)
462-
cache.set(groupId, groupToReturn)
457+
458+
// set the group in cache only if it is having the `oldId`
459+
if (groupToReturn.oldId && groupToReturn.oldId.length > 0) cache.set(groupId, groupToReturn)
463460

464461
if (!isAdmin) delete groupToReturn.status
465462

@@ -504,7 +501,9 @@ async function getGroup(currentUser, groupId, criteria) {
504501
})
505502

506503
groupToReturn.flattenGroupIdTree = flattenGroupIdTree
507-
cache.set(groupId, groupToReturn)
504+
505+
// set the group in cache only if it is having the `oldId`
506+
if (groupToReturn.oldId && groupToReturn.oldId.length > 0) cache.set(groupId, groupToReturn)
508507
}
509508
} else if (criteria.includeParentGroup && !groupToReturn.parentGroups) {
510509
// find parent groups

0 commit comments

Comments
 (0)