diff --git a/daemon.py b/daemon.py index cb23c161..1afd1e58 100644 --- a/daemon.py +++ b/daemon.py @@ -6671,7 +6671,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, nickname, self.server.domain, postFilename, - self.server.debug) + self.server.debug, + self.server.recentPostsCache) if callingDomain.endswith('.onion') and \ self.server.onionDomain: actorStr = \ diff --git a/delete.py b/delete.py index 5c966784..e26002fe 100644 --- a/delete.py +++ b/delete.py @@ -227,7 +227,8 @@ def deletePostPub(session, baseDir: str, federationList: [], def outboxDelete(baseDir: str, httpPrefix: str, nickname: str, domain: str, messageJson: {}, debug: bool, - allowDeletion: bool) -> None: + allowDeletion: bool, + recentPostsCache: {}) -> None: """ When a delete request is received by the outbox from c2s """ if not messageJson.get('type'): @@ -289,6 +290,6 @@ def outboxDelete(baseDir: str, httpPrefix: str, print(messageId) return True deletePost(baseDir, httpPrefix, deleteNickname, deleteDomain, - postFilename, debug) + postFilename, debug, recentPostsCache) if debug: print('DEBUG: post deleted via c2s - ' + postFilename) diff --git a/epicyon.py b/epicyon.py index 376e33c9..663b5064 100644 --- a/epicyon.py +++ b/epicyon.py @@ -1313,7 +1313,7 @@ if args.archive: else: print('Archiving to ' + args.archive + '...') archiveMedia(baseDir, args.archive, archiveWeeks) - archivePosts(baseDir, httpPrefix, args.archive, archiveMaxPosts) + archivePosts(baseDir, httpPrefix, args.archive, {}, archiveMaxPosts) print('Archiving complete') sys.exit() diff --git a/inbox.py b/inbox.py index 8cf40675..aa1efa10 100644 --- a/inbox.py +++ b/inbox.py @@ -1240,7 +1240,8 @@ def receiveDelete(session, handle: str, isGroup: bool, baseDir: str, httpPrefix: str, domain: str, port: int, sendThreads: [], postLog: [], cachedWebfingers: {}, personCache: {}, messageJson: {}, federationList: [], - debug: bool, allowDeletion: bool) -> bool: + debug: bool, allowDeletion: bool, + recentPostsCache: {}) -> bool: """Receives a Delete activity within the POST section of HTTPServer """ if messageJson['type'] != 'Delete': @@ -1305,7 +1306,8 @@ def receiveDelete(session, handle: str, isGroup: bool, baseDir: str, print(messageId) return True deletePost(baseDir, httpPrefix, handle.split('@')[0], - handle.split('@')[1], postFilename, debug) + handle.split('@')[1], postFilename, debug, + recentPostsCache) if debug: print('DEBUG: post deleted - ' + postFilename) return True @@ -2045,7 +2047,8 @@ def inboxAfterCapabilities(recentPostsCache: {}, maxRecentPosts: int, personCache, messageJson, federationList, - debug, allowDeletion): + debug, allowDeletion, + recentPostsCache): if debug: print('DEBUG: Delete accepted from ' + actor) return False diff --git a/outbox.py b/outbox.py index 291456ce..32179dec 100644 --- a/outbox.py +++ b/outbox.py @@ -299,7 +299,8 @@ def postMessageToOutbox(messageJson: {}, postToNickname: str, outboxDelete(baseDir, httpPrefix, postToNickname, domain, messageJson, debug, - allowDeletion) + allowDeletion, + recentPostsCache) if debug: print('DEBUG: handle block requests') diff --git a/posts.py b/posts.py index 4b1a09d8..02920747 100644 --- a/posts.py +++ b/posts.py @@ -2718,17 +2718,21 @@ def createBoxIndexed(recentPostsCache: {}, def expireCache(baseDir: str, personCache: {}, - httpPrefix: str, archiveDir: str, maxPostsInBox=32000): + httpPrefix: str, archiveDir: str, + recentPostsCache: {}, + maxPostsInBox=32000): """Thread used to expire actors from the cache and archive old posts """ while True: # once per day time.sleep(60 * 60 * 24) expirePersonCache(baseDir, personCache) - archivePosts(baseDir, httpPrefix, archiveDir, maxPostsInBox) + archivePosts(baseDir, httpPrefix, archiveDir, recentPostsCache, + maxPostsInBox) def archivePosts(baseDir: str, httpPrefix: str, archiveDir: str, + recentPostsCache: {}, maxPostsInBox=32000) -> None: """Archives posts for all accounts """ @@ -2760,18 +2764,19 @@ def archivePosts(baseDir: str, httpPrefix: str, archiveDir: str, handle + '/inbox' archivePostsForPerson(httpPrefix, nickname, domain, baseDir, 'inbox', archiveSubdir, - maxPostsInBox) + recentPostsCache, maxPostsInBox) if archiveDir: archiveSubdir = archiveDir + '/accounts/' + \ handle + '/outbox' archivePostsForPerson(httpPrefix, nickname, domain, baseDir, 'outbox', archiveSubdir, - maxPostsInBox) + recentPostsCache, maxPostsInBox) def archivePostsForPerson(httpPrefix: str, nickname: str, domain: str, baseDir: str, boxname: str, archiveDir: str, + recentPostsCache: {}, maxPostsInBox=32000) -> None: """Retain a maximum number of posts within the given box Move any others to an archive directory @@ -2855,7 +2860,8 @@ def archivePostsForPerson(httpPrefix: str, nickname: str, domain: str, if os.path.isfile(repliesPath): os.rename(repliesPath, archivePath) else: - deletePost(baseDir, httpPrefix, nickname, domain, filePath, False) + deletePost(baseDir, httpPrefix, nickname, domain, + filePath, False, recentPostsCache) # remove cached html posts postCacheFilename = \ diff --git a/tests.py b/tests.py index 906f6f42..9cd7d21d 100644 --- a/tests.py +++ b/tests.py @@ -1076,8 +1076,8 @@ def testCreatePerson(): deleteAllPosts(baseDir, nickname, domain, 'outbox') setDisplayNickname(baseDir, nickname, domain, 'badger') setBio(baseDir, nickname, domain, 'Randomly roaming in your backyard') - archivePostsForPerson(nickname, domain, baseDir, 'inbox', None, 4) - archivePostsForPerson(nickname, domain, baseDir, 'outbox', None, 4) + archivePostsForPerson(nickname, domain, baseDir, 'inbox', None, {}, 4) + archivePostsForPerson(nickname, domain, baseDir, 'outbox', None, {}, 4) createPublicPost(baseDir, nickname, domain, port, httpPrefix, "G'day world!", False, True, clientToServer, None, None, useBlurhash, None, None, diff --git a/utils.py b/utils.py index 944ebb60..76e66b3d 100644 --- a/utils.py +++ b/utils.py @@ -444,7 +444,7 @@ def isReplyToBlogPost(baseDir: str, nickname: str, domain: str, def deletePost(baseDir: str, httpPrefix: str, nickname: str, domain: str, postFilename: str, - debug: bool) -> None: + debug: bool, recentPostsCache: {}) -> None: """Recursively deletes a post and its replies and attachments """ postJsonObject = loadJson(postFilename, 1) @@ -463,6 +463,14 @@ def deletePost(baseDir: str, httpPrefix: str, postJsonObject): return + # remove from recent posts cache in memory + postId = \ + postJsonObject['id'].replace('/activity', '').replace('/', '#') + if postId in recentPostsCache['index']: + recentPostsCache['index'].remove(postId) + if recentPostsCache['json'].get(postId): + del recentPostsCache['json'][postId] + # remove any attachment removeAttachment(baseDir, httpPrefix, domain, postJsonObject) @@ -543,7 +551,8 @@ def deletePost(baseDir: str, httpPrefix: str, if replyFile: if os.path.isfile(replyFile): deletePost(baseDir, httpPrefix, - nickname, domain, replyFile, debug) + nickname, domain, replyFile, debug, + recentPostsCache) # remove the replies file os.remove(repliesFilename) # finally, remove the post itself