Skip to content

Commit

Permalink
garbage collect more Objects, everything except actors, and everythin…
Browse files Browse the repository at this point in the history
…g deleted

for #1703, #1149
  • Loading branch information
snarfed committed Jan 21, 2025
1 parent ab5161b commit 35bd392
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 3 additions & 4 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@

# auto delete most old objects via the Object.expire property
# https://cloud.google.com/datastore/docs/ttl
DONT_EXPIRE_OBJECT_TYPES = \
as1.ACTOR_TYPES | as1.POST_TYPES | set(('event', 'question'))
DONT_EXPIRE_OBJECT_TYPES = as1.ACTOR_TYPES
OBJECT_EXPIRE_AGE = timedelta(days=90)

GET_ORIGINALS_CACHE_EXPIRATION = timedelta(days=1)
Expand Down Expand Up @@ -1001,14 +1000,14 @@ def __init__(self, *args, **kwargs):
self.lock = Lock()

def _expire(self):
"""Maybe automatically delete this Object after 90d using a TTL policy.
"""Automatically delete most Objects after a while using a TTL policy.
https://cloud.google.com/datastore/docs/ttl
They recommend not indexing TTL properties:
https://cloud.google.com/datastore/docs/ttl#ttl_properties_and_indexes
"""
if self.type not in DONT_EXPIRE_OBJECT_TYPES:
if self.deleted or self.type not in DONT_EXPIRE_OBJECT_TYPES:
return (self.updated or util.now()) + OBJECT_EXPIRE_AGE

expire = ndb.ComputedProperty(_expire, indexed=False)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,15 @@ def test_expire(self):
obj = Object(id='a', our_as1={'objectType': 'activity', 'verb': 'update'})
self.assertEqual(NOW + OBJECT_EXPIRE_AGE, obj.expire)

obj.our_as1['objectType'] = 'note'
self.assertEqual(NOW + OBJECT_EXPIRE_AGE, obj.expire)

obj.our_as1['objectType'] = 'person'
self.assertIsNone(obj.expire)

obj.deleted = True
self.assertEqual(NOW + OBJECT_EXPIRE_AGE, obj.expire)

def test_put_adds_removes_activity_label(self):
obj = Object(id='x#y', our_as1={})
obj.put()
Expand Down

0 comments on commit 35bd392

Please sign in to comment.