ndb caching: drop users and profile objects back down to 2h

pull/1734/head
Ryan Barrett 2025-01-28 14:22:29 -08:00
rodzic 694b613c79
commit 96819770df
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 3 dodań i 13 usunięć

Wyświetl plik

@ -419,7 +419,7 @@ PROFILE_ID_RE = re.compile(
""", re.VERBOSE)
def global_cache_timeout_policy(key):
"""Cache users and profile objects indefinitely, everything else 2h.
"""Cache everything for 2h.
Args:
key (google.cloud.datastore.key.Key or google.cloud.ndb.key.Key):
@ -428,15 +428,6 @@ def global_cache_timeout_policy(key):
Returns:
int: cache expiration for this object, in seconds
"""
if isinstance(key, Key):
# use internal google.cloud.datastore.key.Key
# https://github.com/googleapis/python-ndb/issues/987
key = key._key
if (key and (key.kind in ('ActivityPub', 'ATProto', 'MagicKey')
or key.kind == 'Object' and PROFILE_ID_RE.search(key.name))):
return None
return int(NDB_MEMCACHE_TIMEOUT.total_seconds())

Wyświetl plik

@ -113,7 +113,6 @@ class CommonTest(TestCase):
with app.test_request_context(base_url='https://bsky.brid.gy', path='/foo'):
self.assertEqual('https://bsky.brid.gy/asdf', common.host_url('asdf'))
@skip
def test_cache_policy(self):
for id in 'did:plc:foo', 'did:web:foo':
self.assertTrue(common.cache_policy(Object(id=id).key))
@ -126,7 +125,7 @@ class CommonTest(TestCase):
Object(id='at://did:plc:user/app.bsky.actor.profile/self'),
Follower(id='abc'),
):
self.assertFalse(common.cache_policy(obj.key))
self.assertTrue(common.cache_policy(obj.key))
def test_global_cache_timeout_policy(self):
for obj in (
@ -139,7 +138,7 @@ class CommonTest(TestCase):
Object(id='did:web:foo.com'),
Object(id='at://did:plc:user/app.bsky.actor.profile/self'),
):
self.assertIsNone(common.global_cache_timeout_policy(obj.key._key))
self.assertEqual(7200, common.global_cache_timeout_policy(obj.key._key))
for obj in (
Follower(id='abc'),