fix webmention endpoint discovery cache key

#423
pull/448/head
Ryan Barrett 2023-03-11 12:14:48 -08:00
rodzic 76e26a7c2c
commit 9cc8451182
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 26 dodań i 1 usunięć

Wyświetl plik

@ -162,8 +162,32 @@ def redirect_unwrap(val):
return val
def webmention_endpoint_cache_key(url):
"""Returns cache key for a cached webmention endpoint for a given URL.
Just the domain by default. If the URL is the home page, ie path is / , the
key includes a / at the end, so that we cache webmention endpoints for home
pages separate from other pages. https://github.com/snarfed/bridgy/issues/701
Example: 'snarfed.org /'
https://github.com/snarfed/bridgy-fed/issues/423
Adapted from bridgy/util.py.
"""
parsed = urllib.parse.urlparse(url)
key = parsed.netloc
if parsed.path in ('', '/'):
key += ' /'
# logger.debug(f'wm cache key {key}')
return key
@cachetools.cached(cachetools.TTLCache(50000, 60 * 60 * 2), # 2h expiration
lock=threading.Lock())
key=webmention_endpoint_cache_key,
lock=threading.Lock(),
info=True)
def webmention_discover(url, **kwargs):
"""Thin caching wrapper around :func:`webmention.discover`."""
return webmention.discover(url, **kwargs)

Wyświetl plik

@ -327,6 +327,7 @@ def send_webmentions(obj, proxy=None):
try:
endpoint = common.webmention_discover(target.uri).endpoint
# logger.debug(f'wm cache info {common.webmention_discover.cache_info()}')
if endpoint:
webmention.send(endpoint, wm_source, target.uri)
logger.info('Success!')