mirror of https://gitlab.com/bashrc2/epicyon
Move cache function
parent
f5c427d8cc
commit
24a6f3ca0d
34
cache.py
34
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
34
utils.py
34
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
|
||||
|
|
Loading…
Reference in New Issue