diff --git a/cache.py b/cache.py index bc8c7ab90..46143de8c 100644 --- a/cache.py +++ b/cache.py @@ -410,3 +410,37 @@ def remove_avatar_from_cache(base_dir: str, actor_str: str) -> None: print('EX: remove_avatar_from_cache ' + 'unable to delete cached avatar ' + str(avatar_filename)) + + +def clear_from_post_caches(base_dir: str, recent_posts_cache: {}, + post_id: str) -> None: + """Clears cached html for the given post, so that edits + to news will appear + """ + filename = '/postcache/' + post_id + '.html' + dir_str = data_dir(base_dir) + for _, dirs, _ in os.walk(dir_str): + for acct in dirs: + if '@' not in acct: + continue + if acct.startswith('inbox@') or acct.startswith('Actor@'): + continue + cache_dir = os.path.join(dir_str, acct) + post_filename = cache_dir + filename + if os.path.isfile(post_filename): + try: + os.remove(post_filename) + except OSError: + print('EX: clear_from_post_caches file not removed ' + + str(post_filename)) + # if the post is in the recent posts cache then remove it + if recent_posts_cache.get('index'): + if post_id in recent_posts_cache['index']: + recent_posts_cache['index'].remove(post_id) + if recent_posts_cache.get('json'): + if recent_posts_cache['json'].get(post_id): + del recent_posts_cache['json'][post_id] + if recent_posts_cache.get('html'): + if recent_posts_cache['html'].get(post_id): + del recent_posts_cache['html'][post_id] + break diff --git a/daemon_post_newswire.py b/daemon_post_newswire.py index b0461d5d0..cebd36dfb 100644 --- a/daemon_post_newswire.py +++ b/daemon_post_newswire.py @@ -11,8 +11,8 @@ import os import errno from socket import error as SocketError from flags import is_editor +from cache import clear_from_post_caches from utils import data_dir -from utils import clear_from_post_caches from utils import remove_id_ending from utils import save_json from utils import first_paragraph_from_string diff --git a/newsdaemon.py b/newsdaemon.py index 7c3a4575d..042ded59d 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -32,7 +32,6 @@ from utils import get_full_domain from utils import load_json from utils import save_json from utils import get_status_number -from utils import clear_from_post_caches from utils import dangerous_markup from utils import local_actor_url from utils import text_in_file @@ -40,6 +39,7 @@ from utils import data_dir from session import create_session from threads import begin_thread from webapp_hashtagswarm import store_hash_tags +from cache import clear_from_post_caches def _update_feeds_outbox_index(base_dir: str, domain: str, diff --git a/utils.py b/utils.py index d0905aa6d..b7397649b 100644 --- a/utils.py +++ b/utils.py @@ -1899,40 +1899,6 @@ def locate_news_arrival(base_dir: str, domain: str, return None -def clear_from_post_caches(base_dir: str, recent_posts_cache: {}, - post_id: str) -> None: - """Clears cached html for the given post, so that edits - to news will appear - """ - filename = '/postcache/' + post_id + '.html' - dir_str = data_dir(base_dir) - for _, dirs, _ in os.walk(dir_str): - for acct in dirs: - if '@' not in acct: - continue - if acct.startswith('inbox@') or acct.startswith('Actor@'): - continue - cache_dir = os.path.join(dir_str, acct) - post_filename = cache_dir + filename - if os.path.isfile(post_filename): - try: - os.remove(post_filename) - except OSError: - print('EX: clear_from_post_caches file not removed ' + - str(post_filename)) - # if the post is in the recent posts cache then remove it - if recent_posts_cache.get('index'): - if post_id in recent_posts_cache['index']: - recent_posts_cache['index'].remove(post_id) - if recent_posts_cache.get('json'): - if recent_posts_cache['json'].get(post_id): - del recent_posts_cache['json'][post_id] - if recent_posts_cache.get('html'): - if recent_posts_cache['html'].get(post_id): - del recent_posts_cache['html'][post_id] - break - - def locate_post(base_dir: str, nickname: str, domain: str, post_url: str, replies: bool = False) -> str: """Returns the filename for the given status post url