Skip to content

Commit

Permalink
Fix the timeline in sync store growing indefinitely
Browse files Browse the repository at this point in the history
  • Loading branch information
nexy7574 committed Jan 30, 2025
1 parent 6eba492 commit 2b81ecc
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/niobot/utils/sync_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,6 @@ async def insert_state_event(
new_event = new_event.source["source"]
except KeyError:
new_event = new_event.source
self.log.warning(
"Event %r does not have a source key, falling back to the event itself. This may result in "
"an invalid replay.",
new_event,
)
# Just do some basic validation first
for key in ("type", "event_id", "sender"):
if key not in new_event:
Expand Down Expand Up @@ -403,11 +398,6 @@ async def insert_timeline_event(
new_event = new_event.source["source"]
except KeyError:
new_event = new_event.source
self.log.warning(
"Event %r does not have a source key, falling back to the event itself. This may result in "
"an invalid replay.",
new_event,
)
# Just do some basic validation first
for key in ("type", "event_id", "sender"):
if key not in new_event:
Expand All @@ -426,6 +416,8 @@ async def insert_timeline_event(
dumped_timeline = dumped_timeline[:512] + "..."
self.log.debug("Appending event %r to timeline %r.", new_event, dumped_timeline)
existing_timeline.append(new_event)
if len(existing_timeline) > 10:
existing_timeline = existing_timeline[-10:]
self.log.debug("Room %r now has %d timeline events.", room_id, len(existing_timeline))
await self._db.execute(
f'UPDATE "{table}" SET timeline=? WHERE room_id=?',
Expand Down

0 comments on commit 2b81ecc

Please sign in to comment.