From e3c05562fd54411b5cb92544e19f359f1d370d8e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 19 Jan 2020 20:58:50 +0000 Subject: [PATCH] Update @nickname in actors cache --- daemon.py | 2 +- person.py | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/daemon.py b/daemon.py index 2513112b..6b933f30 100644 --- a/daemon.py +++ b/daemon.py @@ -3922,7 +3922,7 @@ class PubServer(BaseHTTPRequestHandler): except Exception as e: print('WARN: Unable to save token for '+loginNickname+' '+str(e)) - personUpgradeActor(None,loginHandle, \ + personUpgradeActor(self.server.baseDir,None,loginHandle, \ self.server.baseDir+'/accounts/'+loginHandle+'.json') self.server.tokensLookup[self.server.tokens[loginNickname]]=loginNickname diff --git a/person.py b/person.py index 4d362c69..d58ee021 100644 --- a/person.py +++ b/person.py @@ -373,9 +373,10 @@ def createCapabilitiesInbox(baseDir: str,nickname: str,domain: str,port: int, \ """ return createPersonBase(baseDir,nickname,domain,port,httpPrefix,True,None) -def personUpgradeActor(personJson: {},handle: str,filename: str) -> None: +def personUpgradeActor(baseDir: str,personJson: {},handle: str,filename: str) -> None: """Alter the actor to add any new properties """ + updateActor=False if not os.path.isfile(filename): print('WARN: actor file not found '+filename) return @@ -389,8 +390,25 @@ def personUpgradeActor(personJson: {},handle: str,filename: str) -> None: 'locationPrimary':True, 'locationDeleted':False }] - saveJson(personJson,filename) print('Nomadic locations added to to actor '+handle) + updateActor=True + + if updateActor: + saveJson(personJson,filename) + + # also update the actor within the cache + actorCacheFilename= \ + baseDir+'/accounts/cache/actors/'+ \ + personJson['id'].replace('/','#')+'.json' + if os.path.isfile(actorCacheFilename): + saveJson(personJson,actorCacheFilename) + + # update domain/@nickname in actors cache + actorCacheFilename= \ + baseDir+'/accounts/cache/actors/'+ \ + personJson['id'].replace('/users/','/@').replace('/','#')+'.json' + if os.path.isfile(actorCacheFilename): + saveJson(personJson,actorCacheFilename) def personLookup(domain: str,path: str,baseDir: str) -> {}: """Lookup the person for an given nickname @@ -426,7 +444,7 @@ def personLookup(domain: str,path: str,baseDir: str) -> {}: if not os.path.isfile(filename): return None personJson=loadJson(filename) - personUpgradeActor(personJson,handle,filename) + personUpgradeActor(baseDir,personJson,handle,filename) #if not personJson: # personJson={"user": "unknown"} return personJson