mirror of https://gitlab.com/bashrc2/epicyon
Expire cached announces
parent
1a74211625
commit
6a83bf0246
|
@ -22114,6 +22114,7 @@ def run_daemon(max_hashtags: int,
|
||||||
httpd.maxMessageLength = 64000
|
httpd.maxMessageLength = 64000
|
||||||
# Maximum overall number of posts per box
|
# Maximum overall number of posts per box
|
||||||
httpd.maxPostsInBox = 32000
|
httpd.maxPostsInBox = 32000
|
||||||
|
httpd.maxCacheAgeDays = 30
|
||||||
httpd.domain = domain
|
httpd.domain = domain
|
||||||
httpd.port = port
|
httpd.port = port
|
||||||
httpd.domain_full = get_full_domain(domain, port)
|
httpd.domain_full = get_full_domain(domain, port)
|
||||||
|
@ -22259,7 +22260,8 @@ def run_daemon(max_hashtags: int,
|
||||||
httpd.http_prefix,
|
httpd.http_prefix,
|
||||||
archive_dir,
|
archive_dir,
|
||||||
httpd.recent_posts_cache,
|
httpd.recent_posts_cache,
|
||||||
httpd.maxPostsInBox), daemon=True)
|
httpd.maxPostsInBox,
|
||||||
|
httpd.maxCacheAgeDays), daemon=True)
|
||||||
begin_thread(httpd.thrCache, 'run_daemon thrCache')
|
begin_thread(httpd.thrCache, 'run_daemon thrCache')
|
||||||
|
|
||||||
# number of mins after which sending posts or updates will expire
|
# number of mins after which sending posts or updates will expire
|
||||||
|
|
|
@ -585,6 +585,9 @@ def _command_options() -> None:
|
||||||
parser.add_argument('--maxposts', dest='archiveMaxPosts', type=int,
|
parser.add_argument('--maxposts', dest='archiveMaxPosts', type=int,
|
||||||
default=32000,
|
default=32000,
|
||||||
help='Maximum number of posts in in/outbox')
|
help='Maximum number of posts in in/outbox')
|
||||||
|
parser.add_argument('--maxCacheAgeDays', dest='maxCacheAgeDays', type=int,
|
||||||
|
default=30,
|
||||||
|
help='Maximum age of files in the announce cache')
|
||||||
parser.add_argument('--minimumvotes', dest='minimumvotes', type=int,
|
parser.add_argument('--minimumvotes', dest='minimumvotes', type=int,
|
||||||
default=1,
|
default=1,
|
||||||
help='Minimum number of votes to remove or add' +
|
help='Minimum number of votes to remove or add' +
|
||||||
|
@ -2832,7 +2835,8 @@ def _command_options() -> None:
|
||||||
# archiving is for non-instance posts
|
# archiving is for non-instance posts
|
||||||
archive_media(base_dir, argb.archive, argb.archiveWeeks)
|
archive_media(base_dir, argb.archive, argb.archiveWeeks)
|
||||||
archive_posts(base_dir, http_prefix, argb.archive, {},
|
archive_posts(base_dir, http_prefix, argb.archive, {},
|
||||||
argb.archiveMaxPosts)
|
argb.archiveMaxPosts,
|
||||||
|
argb.maxCacheAgeDays)
|
||||||
print('Archiving complete')
|
print('Archiving complete')
|
||||||
# expiry is for instance posts, where an expiry period
|
# expiry is for instance posts, where an expiry period
|
||||||
# has been set within profile settings
|
# has been set within profile settings
|
||||||
|
|
44
posts.py
44
posts.py
|
@ -4265,7 +4265,8 @@ def _create_box_indexed(recent_posts_cache: {},
|
||||||
def expire_cache(base_dir: str, person_cache: {},
|
def expire_cache(base_dir: str, person_cache: {},
|
||||||
http_prefix: str, archive_dir: str,
|
http_prefix: str, archive_dir: str,
|
||||||
recent_posts_cache: {},
|
recent_posts_cache: {},
|
||||||
max_posts_in_box: int):
|
max_posts_in_box: int,
|
||||||
|
max_cache_age_days: int):
|
||||||
"""Thread used to expire actors from the cache and archive old posts
|
"""Thread used to expire actors from the cache and archive old posts
|
||||||
"""
|
"""
|
||||||
while True:
|
while True:
|
||||||
|
@ -4273,12 +4274,42 @@ def expire_cache(base_dir: str, person_cache: {},
|
||||||
time.sleep(60 * 60 * 24)
|
time.sleep(60 * 60 * 24)
|
||||||
expire_person_cache(person_cache)
|
expire_person_cache(person_cache)
|
||||||
archive_posts(base_dir, http_prefix, archive_dir, recent_posts_cache,
|
archive_posts(base_dir, http_prefix, archive_dir, recent_posts_cache,
|
||||||
max_posts_in_box)
|
max_posts_in_box, max_cache_age_days)
|
||||||
|
|
||||||
|
|
||||||
|
def _expire_announce_cache_for_person(base_dir: str,
|
||||||
|
nickname: str, domain: str,
|
||||||
|
max_age_days: int, debug: bool) -> int:
|
||||||
|
"""Expires entries within the announces cache
|
||||||
|
"""
|
||||||
|
cache_dir = \
|
||||||
|
acct_dir(base_dir, nickname, domain) + '/cache/announce/' + nickname
|
||||||
|
if not os.path.isdir(cache_dir):
|
||||||
|
return 0
|
||||||
|
expired_post_count = 0
|
||||||
|
posts_in_cache = os.scandir(cache_dir)
|
||||||
|
for cache_filename in posts_in_cache:
|
||||||
|
cache_filename = cache_filename.name
|
||||||
|
# Time of file creation
|
||||||
|
full_filename = os.path.join(cache_dir, cache_filename)
|
||||||
|
if not os.path.isfile(full_filename):
|
||||||
|
continue
|
||||||
|
last_modified = file_last_modified(full_filename)
|
||||||
|
# get time difference
|
||||||
|
if not valid_post_date(last_modified, max_age_days, debug):
|
||||||
|
try:
|
||||||
|
os.remove(full_filename)
|
||||||
|
except OSError:
|
||||||
|
print('EX: unable to delete from announce cache ' +
|
||||||
|
full_filename)
|
||||||
|
expired_post_count += 1
|
||||||
|
return expired_post_count
|
||||||
|
|
||||||
|
|
||||||
def archive_posts(base_dir: str, http_prefix: str, archive_dir: str,
|
def archive_posts(base_dir: str, http_prefix: str, archive_dir: str,
|
||||||
recent_posts_cache: {},
|
recent_posts_cache: {},
|
||||||
max_posts_in_box=32000) -> None:
|
max_posts_in_box: int = 32000,
|
||||||
|
max_cache_age_days: int = 30) -> None:
|
||||||
"""Archives posts for all accounts
|
"""Archives posts for all accounts
|
||||||
"""
|
"""
|
||||||
if max_posts_in_box == 0:
|
if max_posts_in_box == 0:
|
||||||
|
@ -4315,6 +4346,13 @@ def archive_posts(base_dir: str, http_prefix: str, archive_dir: str,
|
||||||
nickname, domain, base_dir,
|
nickname, domain, base_dir,
|
||||||
'inbox', archive_subdir,
|
'inbox', archive_subdir,
|
||||||
recent_posts_cache, max_posts_in_box)
|
recent_posts_cache, max_posts_in_box)
|
||||||
|
expired_announces = \
|
||||||
|
_expire_announce_cache_for_person(base_dir,
|
||||||
|
nickname, domain,
|
||||||
|
max_cache_age_days, True)
|
||||||
|
if expired_announces > 0:
|
||||||
|
print('Expired ' + str(expired_announces) +
|
||||||
|
' cached announces')
|
||||||
if archive_dir:
|
if archive_dir:
|
||||||
archive_subdir = archive_dir + '/accounts/' + \
|
archive_subdir = archive_dir + '/accounts/' + \
|
||||||
handle + '/outbox'
|
handle + '/outbox'
|
||||||
|
|
Loading…
Reference in New Issue