From edfdde0a1e3a3bf8335a9826feeb484aca69b2c6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 7 Apr 2017 15:51:52 +0300 Subject: refactor: add message id cache to context --- distixlib/plugins/import_mail_plugin.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/distixlib/plugins/import_mail_plugin.py b/distixlib/plugins/import_mail_plugin.py index 56ad188..a1e5443 100644 --- a/distixlib/plugins/import_mail_plugin.py +++ b/distixlib/plugins/import_mail_plugin.py @@ -64,9 +64,8 @@ class ImportMailPlugin(cliapp.Plugin): context.repo.require_clean_working_tree() context.all_ticket_ids = context.store.get_ticket_ids() - cache = _MessageIdCache() filenames = self._import_msg_to_ticket_store( - context, msg, cache, key, value) + context, msg, key, value) if filenames: context.repo.commit_changes(filenames, self.commit_msg) @@ -89,7 +88,6 @@ class ImportMailPlugin(cliapp.Plugin): context.repo.require_clean_working_tree() context.all_ticket_ids = context.store.get_ticket_ids() - cache = _MessageIdCache() filenames = [] if self.app.settings['quiet']: progress = _QuietProgressReporter() @@ -100,7 +98,7 @@ class ImportMailPlugin(cliapp.Plugin): for msg in folder: progress.next_msg() filenames += self._import_msg_to_ticket_store( - context, msg, cache, key, value) + context, msg, key, value) filenames += context.store.save_changes() if filenames: context.repo.commit_changes(filenames, self.commit_msg) @@ -125,10 +123,10 @@ class ImportMailPlugin(cliapp.Plugin): return email.message_from_file(f) def _import_msg_to_ticket_store( - self, context, msg, cache, key, value): + self, context, msg, key, value): referenced_ids = self._find_tickets_with_mails_referenced_by_msg( - context.store, context.all_ticket_ids, msg, cache) + context.store, context.all_ticket_ids, msg, context.cache) msg_ids = distixlib.get_ids_from_message(msg) filenames = [] @@ -138,14 +136,14 @@ class ImportMailPlugin(cliapp.Plugin): ticket = context.store.get_ticket(ticket_id) ticket.add_message(msg) self._set_key_value(ticket, key, value) - cache.add_msg_ids_for_ticket_id( + context.cache.add_msg_ids_for_ticket_id( ticket.get_ticket_id(), msg_ids) else: if not self._is_already_imported( context.store, msg, context.all_ticket_ids): new_ticket = self._create_ticket_from_msg(context.repo, msg) self._set_key_value(new_ticket, key, value) - cache.add_msg_ids_for_ticket_id( + context.cache.add_msg_ids_for_ticket_id( new_ticket.get_ticket_id(), msg_ids) context.all_ticket_ids.append(new_ticket.get_ticket_id()) filenames = context.store.add_ticket(new_ticket) @@ -236,6 +234,8 @@ class _ImportContext(object): def __init__(self): self.repo = None self.store = None + self.all_ticket_ids = None + self.cache = _MessageIdCache() def set_repo(self, repo): self.repo = repo -- cgit v1.2.1