From 91058ea30f5ba1d3188aaf4b464a1469413d746a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 25 Nov 2019 14:05:59 +0000 Subject: [PATCH] Update post cache when receiving question updates --- daemon.py | 5 +++-- inbox.py | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/daemon.py b/daemon.py index 746a4c615..ce22f5cd0 100644 --- a/daemon.py +++ b/daemon.py @@ -230,8 +230,9 @@ class PubServer(BaseHTTPRequestHandler): getCachedPostFilename(self.server.baseDir, \ nickname, \ self.server.domain,messageJson) - if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + if cachedPostFilename: + if os.path.isfile(cachedPostFilename): + os.remove(cachedPostFilename) # remove from memory cache removePostFromCache(messageJson,self.server.recentPostsCache) else: diff --git a/inbox.py b/inbox.py index a5848b1a0..e64b42bab 100644 --- a/inbox.py +++ b/inbox.py @@ -12,6 +12,8 @@ import datetime import time import json from shutil import copyfile +from utils import getCachedPostFilename +from utils import removePostFromCache from utils import urlPermitted from utils import createInboxQueueDir from utils import getStatusNumber @@ -741,7 +743,7 @@ def receiveUpdate(session,baseDir: str, \ httpPrefix: str,domain :str,port: int, \ sendThreads: [],postLog: [],cachedWebfingers: {}, \ personCache: {},messageJson: {},federationList: [], \ - debug : bool) -> bool: + nickname: str,debug : bool) -> bool: """Receives an Update activity within the POST section of HTTPServer """ if messageJson['type']!='Update': @@ -769,6 +771,20 @@ def receiveUpdate(session,baseDir: str, \ print('DEBUG: "users" or "profile" missing from actor in '+messageJson['type']) return False + if messageJson['object']['type']=='Question': + # ensure that the cached post is removed if it exists, so + # that it then will be recreated + cachedPostFilename= \ + getCachedPostFilename(baseDir,nickname,domain,messageJson) + if cachedPostFilename: + if os.path.isfile(cachedPostFilename): + os.remove(cachedPostFilename) + # remove from memory cache + removePostFromCache(messageJson,self.server.recentPostsCache) + if debug: + print('DEBUG: Question update was received') + return True + if messageJson['object']['type']=='Person' or \ messageJson['object']['type']=='Application' or \ messageJson['object']['type']=='Group' or \ @@ -2121,6 +2137,7 @@ def runInboxQueue(recentPostsCache: {},maxRecentPosts: int, \ personCache, \ queueJson['post'], \ federationList, \ + queueJson['postNickname'], \ debug): if debug: print('DEBUG: Update accepted from '+keyId)