Load cached automatic content warnings at startup

main
Bob Mottram 2024-01-18 14:03:35 +00:00
parent 5ff61bab0e
commit de88136753
2 changed files with 20 additions and 2 deletions

View File

@ -15,6 +15,7 @@ import email.parser
import urllib.parse import urllib.parse
from shutil import copyfile from shutil import copyfile
from dateutil.parser import parse from dateutil.parser import parse
from utils import is_account_dir
from utils import get_url_from_post from utils import get_url_from_post
from utils import is_right_to_left_text from utils import is_right_to_left_text
from utils import language_right_to_left from utils import language_right_to_left
@ -2268,10 +2269,26 @@ def _load_auto_cw(base_dir: str, nickname: str, domain: str) -> []:
return [] return []
def load_auto_cw_cache(base_dir: str) -> {}:
"""Returns a dictionary containing the automatic content warning lists
for each account
"""
auto_cw_cache = {}
for _, dirs, _ in os.walk(base_dir + '/accounts'):
for handle in dirs:
if not is_account_dir(handle):
continue
nickname = handle.split('@')[0]
domain = handle.split('@')[1]
auto_cw_cache[nickname] = _load_auto_cw(base_dir, nickname, domain)
break
return auto_cw_cache
def add_auto_cw(base_dir: str, nickname: str, domain: str, def add_auto_cw(base_dir: str, nickname: str, domain: str,
subject: str, content: str, subject: str, content: str,
auto_cw_cache: {}) -> str: auto_cw_cache: {}) -> str:
"""Appends any automatic CW to the subject line """Appends any automatic content warnings to the subject line
and returns the new subject line and returns the new subject line
""" """
new_subject = subject new_subject = subject

View File

@ -391,6 +391,7 @@ from utils import get_actor_from_post
from manualapprove import manual_deny_follow_request_thread from manualapprove import manual_deny_follow_request_thread
from manualapprove import manual_approve_follow_request_thread from manualapprove import manual_approve_follow_request_thread
from announce import create_announce from announce import create_announce
from content import load_auto_cw_cache
from content import add_name_emojis_to_tags from content import add_name_emojis_to_tags
from content import load_dogwhistles from content import load_dogwhistles
from content import valid_url_lengths from content import valid_url_lengths
@ -24543,7 +24544,7 @@ def run_daemon(no_of_books: int,
httpd.max_cached_readers = 24 httpd.max_cached_readers = 24
# cache for automatic content warnings # cache for automatic content warnings
httpd.auto_cw_cache = {} httpd.auto_cw_cache = load_auto_cw_cache(base_dir)
# list of websites which are currently down # list of websites which are currently down
httpd.sites_unavailable = load_unavailable_sites(base_dir) httpd.sites_unavailable = load_unavailable_sites(base_dir)