database: no longer store remote actors indefinitely in JSON-LD database, use hot cache instead
This commit is contained in:
parent
692cf89195
commit
5871c40667
|
@ -20,6 +20,9 @@ for inbox in following:
|
|||
following.remove(inbox)
|
||||
DATABASE['relay-list'] = following
|
||||
|
||||
if 'actors' in DATABASE:
|
||||
DATABASE.pop('actors')
|
||||
|
||||
async def database_save():
|
||||
while True:
|
||||
with open(CONFIG['db'], 'w') as f:
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
import aiohttp
|
||||
from .database import DATABASE
|
||||
from . import CONFIG
|
||||
from .http_debug import http_debug
|
||||
|
||||
from cachetools import TTLCache
|
||||
|
||||
|
||||
CACHE_SIZE = CONFIG.get('cache-size', 16384)
|
||||
CACHE_TTL = CONFIG.get('cache-ttl', 3600)
|
||||
|
||||
ACTORS = TTLCache(CACHE_SIZE, CACHE_TTL)
|
||||
|
||||
|
||||
ACTORS = DATABASE.get("actors", {})
|
||||
async def fetch_actor(uri, force=False):
|
||||
if uri in ACTORS and not force:
|
||||
return ACTORS[uri]
|
||||
|
@ -11,5 +18,4 @@ async def fetch_actor(uri, force=False):
|
|||
async with aiohttp.ClientSession(trace_configs=[http_debug()]) as session:
|
||||
async with session.get(uri, headers={'Accept': 'application/activity+json'}) as resp:
|
||||
ACTORS[uri] = (await resp.json(encoding='utf-8', content_type=None))
|
||||
DATABASE["actors"] = ACTORS
|
||||
return ACTORS[uri]
|
||||
|
|
Loading…
Reference in a new issue