|
17 | 17 | from sqlalchemy import bindparam, desc # type: ignore[import-untyped] |
18 | 18 | from sqlalchemy.orm import Session # type: ignore[import-untyped] |
19 | 19 | from sqlalchemy.orm.exc import NoResultFound # type: ignore[import-untyped] |
20 | | -from sqlalchemy.sql.expression import func # type: ignore[import-untyped] |
21 | 20 |
|
22 | 21 | from inbox.contacts.processing import update_contacts_from_message |
23 | 22 | from inbox.crispin import RawMessage |
24 | 23 | from inbox.logging import get_logger |
25 | | -from inbox.models import Account, ActionLog, Folder, Message, MessageCategory |
| 24 | +from inbox.models import Account, Folder, Message, MessageCategory |
26 | 25 | from inbox.models.backends.imap import ImapFolderInfo, ImapUid |
27 | 26 | from inbox.models.category import Category |
28 | 27 | from inbox.models.session import session_scope |
@@ -162,15 +161,6 @@ def update_message_metadata( |
162 | 161 | if old_categories or new_categories: |
163 | 162 | message.updated_at = update_time |
164 | 163 |
|
165 | | - """ |
166 | | - if not message.categories_changes: |
167 | | - # No syncback actions scheduled, so there is no danger of |
168 | | - # overwriting modified local state. |
169 | | - message.categories = categories |
170 | | - else: |
171 | | - _update_categories(session, message, categories) |
172 | | - """ |
173 | | - |
174 | 164 |
|
175 | 165 | def update_metadata( # type: ignore[no-untyped-def] |
176 | 166 | account_id, folder_id, folder_role, new_flags, session |
@@ -367,44 +357,3 @@ def create_imap_message( |
367 | 357 | ) |
368 | 358 |
|
369 | 359 | return imapuid |
370 | | - |
371 | | - |
372 | | -def _update_categories( # type: ignore[no-untyped-def] |
373 | | - db_session, message, synced_categories |
374 | | -) -> None: |
375 | | - now = datetime.utcnow() |
376 | | - |
377 | | - # We make the simplifying assumption that only the latest syncback action |
378 | | - # matters, since it reflects the current local state. |
379 | | - actionlog_id = ( |
380 | | - db_session.query(func.max(ActionLog.id)) |
381 | | - .filter( |
382 | | - ActionLog.namespace_id == message.namespace_id, |
383 | | - ActionLog.table_name == "message", |
384 | | - ActionLog.record_id == message.id, |
385 | | - ActionLog.action.in_(["change_labels", "move"]), |
386 | | - ) |
387 | | - .scalar() |
388 | | - ) |
389 | | - if actionlog_id is not None: |
390 | | - actionlog = db_session.query(ActionLog).get(actionlog_id) |
391 | | - # Do /not/ overwrite message.categories in case of a recent local |
392 | | - # change - namely, a still 'pending' action or one that completed |
393 | | - # recently. |
394 | | - if ( |
395 | | - actionlog.status == "pending" |
396 | | - or (now - actionlog.updated_at).total_seconds() <= 90 |
397 | | - ): |
398 | | - return |
399 | | - |
400 | | - # We completed the syncback action /long enough ago/ (on average and |
401 | | - # with an error margin) that: |
402 | | - # - if it completed successfully, sync has picked it up; so, safe to |
403 | | - # overwrite message.categories |
404 | | - # - if syncback failed, the local changes made can be overwritten |
405 | | - # without confusing the API user. |
406 | | - # TODO[k]/(emfree): Implement proper rollback of local state in this case. |
407 | | - # This is needed in order to pick up future changes to the message, |
408 | | - # the local_changes counter is reset as well. |
409 | | - message.categories = synced_categories |
410 | | - message.categories_changes = False |
0 commit comments