diff options
author | Bruno Wagner <bwagner@riseup.net> | 2016-01-08 17:34:20 -0200 |
---|---|---|
committer | Bruno Wagner <bwagner@riseup.net> | 2016-01-08 17:34:20 -0200 |
commit | db38cc2919fbe5f52d9eb73f45fd89a84da89682 (patch) | |
tree | cccaad5e84f270961587599d3fe696b2db740072 /service | |
parent | 0a29be8e41aa81fd1552b1122bc4ab2a3f2357cf (diff) |
Removed search engine from constant in Indexer
The search engine was being passed as a constant to
the Mail Indexer, that constrained the user agent to
one user (because the search engine is user specific).
I added the search engine as a parameter on the Mail Indexer
initialization so that we can have the Indexer working for
each user.
Diffstat (limited to 'service')
3 files changed, 13 insertions, 18 deletions
diff --git a/service/pixelated/adapter/listeners/mailbox_indexer_listener.py b/service/pixelated/adapter/listeners/mailbox_indexer_listener.py index 8896d742..e2f46769 100644 --- a/service/pixelated/adapter/listeners/mailbox_indexer_listener.py +++ b/service/pixelated/adapter/listeners/mailbox_indexer_listener.py @@ -23,32 +23,31 @@ logger = logging.getLogger(__name__) class MailboxIndexerListener(object): """ Listens for new mails, keeping the index updated """ - SEARCH_ENGINE = None - @classmethod @defer.inlineCallbacks - def listen(cls, account, mailbox_name, mail_store): - listener = MailboxIndexerListener(mailbox_name, mail_store) + def listen(cls, account, mailbox_name, mail_store, search_engine): + listener = MailboxIndexerListener(mailbox_name, mail_store, search_engine) if listener not in (yield account.getMailbox(mailbox_name)).listeners: mbx = yield account.getMailbox(mailbox_name) mbx.addListener(listener) defer.returnValue(listener) - def __init__(self, mailbox_name, mail_store): + def __init__(self, mailbox_name, mail_store, search_engine): self.mailbox_name = mailbox_name self.mail_store = mail_store + self.search_engine = search_engine @defer.inlineCallbacks def newMessages(self, exists, recent): try: - indexed_idents = set(self.SEARCH_ENGINE.search('tag:' + self.mailbox_name.lower(), all_mails=True)) + indexed_idents = set(self.search_engine.search('tag:' + self.mailbox_name.lower(), all_mails=True)) soledad_idents = yield self.mail_store.get_mailbox_mail_ids(self.mailbox_name) soledad_idents = set(soledad_idents) missing_idents = soledad_idents.difference(indexed_idents) - self.SEARCH_ENGINE.index_mails((yield self.mail_store.get_mails(missing_idents))) + self.search_engine.index_mails((yield self.mail_store.get_mails(missing_idents))) except Exception, e: # this is a event handler, don't let exceptions escape logger.error(e) @@ -64,7 +63,6 @@ class MailboxIndexerListener(object): @defer.inlineCallbacks def listen_all_mailboxes(account, search_engine, mail_store): - MailboxIndexerListener.SEARCH_ENGINE = search_engine mailboxes = yield account.account.list_all_mailbox_names() for mailbox_name in mailboxes: - yield MailboxIndexerListener.listen(account, mailbox_name, mail_store) + yield MailboxIndexerListener.listen(account, mailbox_name, mail_store, search_engine) diff --git a/service/test/integration/test_incoming_mail.py b/service/test/integration/test_incoming_mail.py index 8a5540dc..682ca118 100644 --- a/service/test/integration/test_incoming_mail.py +++ b/service/test/integration/test_incoming_mail.py @@ -25,12 +25,11 @@ class IncomingMailTest(SoledadTestBase): @defer.inlineCallbacks def test_message_collection(self): # given - MailboxIndexerListener.SEARCH_ENGINE = self.search_engine mbx = yield self.account.getMailbox('INBOX') input_mail = MailBuilder().build_input_mail() # when - yield MailboxIndexerListener.listen(self.account, 'INBOX', self.mail_store) + yield MailboxIndexerListener.listen(self.account, 'INBOX', self.mail_store, self.search_engine) yield mbx.addMessage(input_mail.raw, [], notify_just_mdoc=False) # then diff --git a/service/test/unit/adapter/test_mailbox_indexer_listener.py b/service/test/unit/adapter/test_mailbox_indexer_listener.py index 9ad3c94d..9d5f4c30 100644 --- a/service/test/unit/adapter/test_mailbox_indexer_listener.py +++ b/service/test/unit/adapter/test_mailbox_indexer_listener.py @@ -35,19 +35,17 @@ class MailboxListenerTest(unittest.TestCase): mailbox.listeners = set() when(mailbox).addListener = lambda x: mailbox.listeners.add(x) - self.assertNotIn(MailboxIndexerListener('INBOX', self.mail_store), mailbox.listeners) + self.assertNotIn(MailboxIndexerListener('INBOX', self.mail_store, mock()), mailbox.listeners) - MailboxIndexerListener.listen(self.account, 'INBOX', self.mail_store) + MailboxIndexerListener.listen(self.account, 'INBOX', self.mail_store, mock()) - self.assertIn(MailboxIndexerListener('INBOX', self.mail_store), mailbox.listeners) + self.assertIn(MailboxIndexerListener('INBOX', self.mail_store, mock()), mailbox.listeners) def test_reindex_missing_idents(self): search_engine = mock() when(search_engine).search('tag:inbox', all_mails=True).thenReturn(['ident1', 'ident2']) - MailboxIndexerListener.SEARCH_ENGINE = search_engine - - listener = MailboxIndexerListener('INBOX', self.mail_store) + listener = MailboxIndexerListener('INBOX', self.mail_store, search_engine) when(self.mail_store).get_mailbox_mail_ids('INBOX').thenReturn({'ident1', 'ident2', 'missing_ident'}) self.mail_store.used_arguments = [] self.mail_store.get_mails = lambda x: self.mail_store.used_arguments.append(x) @@ -59,7 +57,7 @@ class MailboxListenerTest(unittest.TestCase): @defer.inlineCallbacks def test_catches_exceptions_to_not_break_other_listeners(self): when(logger).error(ANY()).thenReturn(None) - listener = MailboxIndexerListener('INBOX', self.mail_store) + listener = MailboxIndexerListener('INBOX', self.mail_store, mock()) yield listener.newMessages(1, 1) |