~ihabunek/toot-discuss

tooi: EventList: limit size of the list v1 APPLIED

Lexi Winter: 1
 EventList: limit size of the list

 1 files changed, 7 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~ihabunek/toot-discuss/patches/48482/mbox | git am -3
Learn more about email & git

[PATCH tooi] EventList: limit size of the list Export this patch

When prepending items to the beginning of the list (which happens when
loading new statuses), limit the size of the list to self.MAX_LENGTH to
prevent it from growing forever.

MAX_LENGTH is currently set to 1024, which should be more than enough
for most users.

This doesn't affect scrolling backward through the timeline: events are
only removed when the timeline is refreshed.
---
 tooi/widgets/event_list.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tooi/widgets/event_list.py b/tooi/widgets/event_list.py
index d16eecf..a96763b 100644
--- a/tooi/widgets/event_list.py
+++ b/tooi/widgets/event_list.py
@@ -14,6 +14,10 @@ class EventList(ListView):
    A ListView that shows a list of events.
    """

    # When prepending events, if we have more than this many events, start removing events from the
    # end.
    MAX_LENGTH = 1024

    DEFAULT_CSS = """
    EventList {
        width: 1fr;
@@ -62,6 +66,9 @@ class EventList(ListView):
        if self.current is not None:
            self.post_message(EventHighlighted(self.current))

        for item in self.query(EventListItem)[self.MAX_LENGTH:]:
            item.remove()

    def focus_event(self, event_id: str):
        for i, item in enumerate(self.query(EventListItem)):
            if item.event.id == event_id:
-- 
2.43.0