Skip to content

Commit

Permalink
refactor retention mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Archento committed Aug 30, 2024
1 parent 0c72136 commit a28162e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions python/src/uagents/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,8 @@ def add_entry(self, entry: EnvelopeHistoryEntry):
def apply_retention_policy(self):
"""Remove entries older than 24 hours"""
cutoff_time = time.time() - 86400
self.envelopes = [e for e in self.envelopes if e.timestamp > cutoff_time]

@field_serializer("envelopes", when_used="always")
def serialize_envelopes_in_order(
self, envelopes: List[EnvelopeHistoryEntry], _info
):
return sorted(envelopes, key=lambda e: e.timestamp)
for e in self.envelopes:
if e.timestamp < cutoff_time:
self.envelopes.remove(e)
else:
break

0 comments on commit a28162e

Please sign in to comment.