From bc8b0b2682522587742ac65091e3ea005c0f94e6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 29 Apr 2017 18:39:29 +0300 Subject: Only load ticket matching requested id --- distixlib/ticket_store.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/distixlib/ticket_store.py b/distixlib/ticket_store.py index 1a8b809..2343e2e 100644 --- a/distixlib/ticket_store.py +++ b/distixlib/ticket_store.py @@ -78,7 +78,10 @@ class TicketStore(object): '''Return a distixlib.Ticket for an existing ticket in the store.''' ticket_id = self._find_ticket_id_from_prefix(ticket_id_or_prefix) - assert ticket_id in self._ticket_cache + if ticket_id not in self._ticket_cache: + ticket_dir = self._get_dir_for_ticket(ticket_id) + ticket = self._load_ticket(ticket_dir) + self._ticket_cache.put(ticket) return self._ticket_cache.get(ticket_id) def _find_ticket_id_from_prefix(self, prefix): @@ -87,8 +90,7 @@ class TicketStore(object): if len(matches) == 1: return matches[0] - tickets = self.get_tickets() - ticket_ids = [t.get_ticket_id() for t in tickets] + ticket_ids = self.get_ticket_ids() matches = self._find_ticket_ids_matching_prefix(ticket_ids, prefix) if len(matches) == 1: return matches[0] -- cgit v1.2.1 From 5e7a8c6b497ed7fa7ffac2c0a80244dd3fa85cde Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 29 Apr 2017 20:03:56 +0300 Subject: Use lightweight versions of tickets for rendering This way, we save memory by not having large numbers of Ticket objects in memory at once. Also, only load into memory tickets while they are neeeded. --- distixlib/plugins/html_plugin.py | 45 ++++++++++++++++++++++++++++++++++------ distixlib/ticket_store.py | 6 ++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/distixlib/plugins/html_plugin.py b/distixlib/plugins/html_plugin.py index 379a83c..2ee8bd1 100644 --- a/distixlib/plugins/html_plugin.py +++ b/distixlib/plugins/html_plugin.py @@ -84,8 +84,10 @@ class StaticSite(object): 'index.html.j2', 'index.html', self._ticket_is_open) self._render_ticket_list( 'closed.html.j2', 'closed.html', self._ticket_is_closed) - for ticket in self._ticket_store.get_tickets(): + for ticket_id in self._ticket_store.get_ticket_ids(): + ticket = self._ticket_store.get_ticket(ticket_id) self._render_ticket(ticket) + self._ticket_store.clear_ticket_cache() self._copy_static_files() def _format_timestamp(self): @@ -129,11 +131,16 @@ class StaticSite(object): return markdown.markdown(text) def _get_tickets(self, condition): - return [ - ticket - for ticket in self._ticket_store.get_tickets() - if condition(ticket) - ] + for ticket_id in self._ticket_store.get_ticket_ids(): + ticket = self._ticket_store.get_ticket(ticket_id) + self._ticket_store.clear_ticket_cache() + if condition(ticket): + lt = TicketLight() + lt.set_ticket_id(ticket_id) + lt.set_title(ticket.get_title()) + lt.set_newest_message_timestamp( + ticket.get_newest_message_timestamp()) + yield lt def _ticket_is_open(self, ticket): return not self._ticket_is_closed(ticket) @@ -163,6 +170,32 @@ class StaticSite(object): f.write(text.encode('UTF8')) +class TicketLight(object): + + def __init__(self): + self._ticket_id = None + self._title = None + self._timestamp = None + + def set_ticket_id(self, ticket_id): + self._ticket_id = ticket_id + + def set_title(self, title): + self._title = title + + def set_newest_message_timestamp(self, timestamp): + self._timestamp = timestamp + + def get_ticket_id(self): + return self._ticket_id + + def get_title(self): + return self._title + + def get_newest_message_timestamp(self): + return self._timestamp + + class UsageError(distixlib.StructuredError): msg = '"html" command must get exactly one argument: the output directory' diff --git a/distixlib/ticket_store.py b/distixlib/ticket_store.py index 2343e2e..fdf5b02 100644 --- a/distixlib/ticket_store.py +++ b/distixlib/ticket_store.py @@ -74,6 +74,9 @@ class TicketStore(object): return os.listdir(self._dirname) return [] + def clear_ticket_cache(self): # pragma: no cover + self._ticket_cache.clear() + def get_ticket(self, ticket_id_or_prefix): '''Return a distixlib.Ticket for an existing ticket in the store.''' @@ -226,3 +229,6 @@ class _TicketCache(object): def get_all(self): return self._known_tickets.values() + + def clear(self): # pragma: no cover + self._known_tickets.clear() -- cgit v1.2.1