summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-04-07 15:51:52 +0300
committerLars Wirzenius <liw@liw.fi>2017-04-07 15:51:52 +0300
commitedfdde0a1e3a3bf8335a9826feeb484aca69b2c6 (patch)
tree20d75fe28dbf45ca64eea0ea0167de8b7d0125ce
parentbe9eeba4c4c92568ad6c473102f5fb91abfca2d1 (diff)
downloaddistix-edfdde0a1e3a3bf8335a9826feeb484aca69b2c6.tar.gz
refactor: add message id cache to context
-rw-r--r--distixlib/plugins/import_mail_plugin.py16
1 files 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