diff options
author | rafael lisboa <rafaelzlisboa@gmail.com> | 2015-05-19 17:04:49 -0300 |
---|---|---|
committer | rafael lisboa <rafaelzlisboa@gmail.com> | 2015-05-19 17:04:49 -0300 |
commit | fcde31733d32021b604a39574cbe47dd7d7f1a0f (patch) | |
tree | bb156ee26b29ea29f77e8b3659d91c3687dd13f7 | |
parent | 6f2481f187ff99a2fe27844c0bc42682da98f2de (diff) |
stop unneeded index rebuild and endless marking of recent docs
(paired with @shyba)
this should stop soledad sync from running repeatedly
- removes all callbacks to the SOLEDAD_DONE_DATA_SYNC event after
they’re called
- avoid re-marking a document as recent if it was already marked
-rw-r--r-- | service/pixelated/adapter/soledad/soledad_writer_mixin.py | 2 | ||||
-rw-r--r-- | service/pixelated/config/app_factory.py | 20 | ||||
-rw-r--r-- | service/pixelated/config/welcome_mail.py | 6 |
3 files changed, 15 insertions, 13 deletions
diff --git a/service/pixelated/adapter/soledad/soledad_writer_mixin.py b/service/pixelated/adapter/soledad/soledad_writer_mixin.py index 9c5eb47a..8e7a46f2 100644 --- a/service/pixelated/adapter/soledad/soledad_writer_mixin.py +++ b/service/pixelated/adapter/soledad/soledad_writer_mixin.py @@ -21,7 +21,7 @@ class SoledadWriterMixin(SoledadDbFacadeMixin, object): def mark_all_as_not_recent(self): for mailbox in ['INBOX', 'DRAFTS', 'SENT', 'TRASH']: rct = self.get_recent_by_mbox(mailbox) - if len(rct) == 0: + if not rct or not rct[0].content['rct']: return rct = rct[0] rct.content['rct'] = [] diff --git a/service/pixelated/config/app_factory.py b/service/pixelated/config/app_factory.py index 96412386..d02472ec 100644 --- a/service/pixelated/config/app_factory.py +++ b/service/pixelated/config/app_factory.py @@ -38,9 +38,11 @@ from leap.common.events import ( events_pb2 as proto ) from twisted.web.server import Site -from .welcome_mail import check_welcome_mail_wrapper +from .welcome_mail import check_welcome_mail CREATE_KEYS_IF_KEYS_DONT_EXISTS_CALLBACK = 12345 +INIT_INDEX_AND_REMOVE_DUPES_CALLBACK = 12346 +CHECK_WELCOME_MAIL_CALLBACK = 12347 def init_index_and_remove_dupes(querier, search_engine, mail_service): @@ -48,14 +50,17 @@ def init_index_and_remove_dupes(querier, search_engine, mail_service): querier.remove_duplicates() search_engine.index_mails(mails=mail_service.all_mails(), callback=querier.mark_all_as_not_recent) + unregister(proto.SOLEDAD_DONE_DATA_SYNC, + uid=INIT_INDEX_AND_REMOVE_DUPES_CALLBACK) return wrapper -def update_index_partial(search_engine, mail_service): - def wrapper(soledad_sync_status): - search_engine.index_mails(mails=mail_service.all_mails()) - +def check_welcome_mail_wrapper(mailbox): + def wrapper(*args, **kwargs): + check_welcome_mail(mailbox) + unregister(proto.SOLEDAD_DONE_DATA_SYNC, + uid=CHECK_WELCOME_MAIL_CALLBACK) return wrapper @@ -108,14 +113,17 @@ def init_app(app, leap_home, leap_session): app.resource.initialize(soledad_querier, keymanager, search_engine, mail_service, draft_service) register(signal=proto.SOLEDAD_DONE_DATA_SYNC, + uid=INIT_INDEX_AND_REMOVE_DUPES_CALLBACK, callback=init_index_and_remove_dupes(querier=soledad_querier, search_engine=search_engine, mail_service=mail_service)) register(signal=proto.SOLEDAD_DONE_DATA_SYNC, + uid=CHECK_WELCOME_MAIL_CALLBACK, callback=check_welcome_mail_wrapper(pixelated_mailboxes.inbox())) - register(signal=proto.SOLEDAD_DONE_DATA_SYNC, uid=CREATE_KEYS_IF_KEYS_DONT_EXISTS_CALLBACK, + register(signal=proto.SOLEDAD_DONE_DATA_SYNC, + uid=CREATE_KEYS_IF_KEYS_DONT_EXISTS_CALLBACK, callback=look_for_user_key_and_create_if_cant_find(leap_session)) reactor.threadpool.adjustPoolsize(20, 40) diff --git a/service/pixelated/config/welcome_mail.py b/service/pixelated/config/welcome_mail.py index 236c4331..5dcbf9bc 100644 --- a/service/pixelated/config/welcome_mail.py +++ b/service/pixelated/config/welcome_mail.py @@ -40,9 +40,3 @@ def build_welcome_mail(): if payload.get_content_type() == 'text/plain': welcome_mail.body = payload.as_string() return welcome_mail - - -def check_welcome_mail_wrapper(mailbox): - def wrapper(*args, **kwargs): - check_welcome_mail(mailbox) - return wrapper |