From 22b4825f3fc5653f5d1064df86d05582c37e85ac Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 25 Mar 2017 13:12:24 +0200 Subject: Maintain and user msg id cache --- distixlib/plugins/import_mail_plugin.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/distixlib/plugins/import_mail_plugin.py b/distixlib/plugins/import_mail_plugin.py index 6e3fb84..2bf9586 100644 --- a/distixlib/plugins/import_mail_plugin.py +++ b/distixlib/plugins/import_mail_plugin.py @@ -141,14 +141,18 @@ class ImportMailPlugin(cliapp.Plugin): msg_ids = self._get_message_ids(msg) for ticket_id in all_ticket_ids: - filenames = store.get_message_filenames(ticket_id) - for filename in filenames: - with open(filename) as f: - other_msg = email.message_from_file(f) - other_ids = self._get_message_ids(other_msg) - if other_ids.intersection(msg_ids): - ticket = store.get_ticket(ticket_id) - tickets.append(ticket) + if ticket_id in cache: + other_ids = cache.get_msg_ids_for_ticket_id(ticket_id) + else: + filenames = store.get_message_filenames(ticket_id) + for filename in filenames: + with open(filename) as f: + other_msg = email.message_from_file(f) + other_ids = self._get_message_ids(other_msg) + cache.add_msg_ids_for_ticket_id(ticket_id, other_ids) + if other_ids.intersection(msg_ids): + ticket = store.get_ticket(ticket_id) + tickets.append(ticket) return tickets -- cgit v1.2.1