Only delete squeaks that are not liked (#880)

This commit is contained in:
Jonathan Zernik 2021-02-22 20:54:32 -08:00 committed by GitHub
parent c4477a9168
commit bfbb4ba335
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View file

@ -90,7 +90,11 @@ class SqueakDb:
@property
def squeak_is_liked(self):
return self.squeaks.c.liked # noqa: E711
return self.squeaks.c.liked
@property
def squeak_is_not_liked(self):
return self.squeaks.c.liked == False # noqa: E711
@property
def squeak_has_no_secret_key(self):
@ -442,10 +446,10 @@ class SqueakDb:
hashes = [bytes.fromhex(row["hash"]) for row in rows]
return hashes
def yield_old_squeaks_to_delete(
def get_old_squeaks_to_delete(
self,
interval_s: int,
) -> Iterator[SqueakEntryWithProfile]:
) -> List[SqueakEntryWithProfile]:
""" Get squeaks older than retention that meet the
criteria for deletion.
"""
@ -459,11 +463,12 @@ class SqueakDb:
)
.where(self.squeak_is_older_than_retention(interval_s))
.where(self.profile_has_no_private_key)
.where(self.squeak_is_not_liked)
)
with self.get_connection() as connection:
result = connection.execute(s)
for row in result:
yield self._parse_squeak_entry_with_profile(row)
rows = result.fetchall()
return [self._parse_squeak_entry_with_profile(row) for row in rows]
def insert_profile(self, squeak_profile: SqueakProfile) -> int:
""" Insert a new squeak profile. """

View file

@ -526,7 +526,7 @@ class SqueakController:
self.payment_processor.start_processing()
def delete_old_squeaks(self):
squeaks_to_delete = self.squeak_db.yield_old_squeaks_to_delete(
squeaks_to_delete = self.squeak_db.get_old_squeaks_to_delete(
self.config.core.squeak_retention_s,
)
for squeak_entry_with_profile in squeaks_to_delete: