Skip to content

Commit

Permalink
Merge pull request #5168 from chrisburr/fix-user-profile-caching
Browse files Browse the repository at this point in the history
[v7r1] Fix caching in UserProfileDB
  • Loading branch information
Andrei Tsaregorodtsev committed Jun 2, 2021
2 parents 6e884fc + 69f0f40 commit 8890c68
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions FrameworkSystem/DB/UserProfileDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ def __getFieldsCached(self, tableName, outFields, condDict):
TTL cache to dramatically improve performance.
"""
key = (tableName, tuple(outFields), tuple(sorted(condDict.items())))
if key not in self.__cache:
result = self.getFields(tableName, outFields, condDict)
if not result['OK']:
return result
data = result['Value']
if len(data) > 0:
objId = data[0][0]
self.updateFields(tableName, ['LastAccess'], ['UTC_TIMESTAMP()'], {'Id': objId})
if key in self.__cache:
return self.__cache[key]
result = self.getFields(tableName, outFields, condDict)
if not result['OK']:
return result
data = result['Value']
if len(data) > 0:
objId = data[0][0]
self.updateFields(tableName, ['LastAccess'], ['UTC_TIMESTAMP()'], {'Id': objId})
self.__cache[key] = result
return self.__cache[key]
return result

def __getObjId(self, objValue, varName, tableName, insertIfMissing=True):
result = self.__getFieldsCached(tableName, ['Id'], {varName: objValue})
Expand Down

0 comments on commit 8890c68

Please sign in to comment.