Skip to content

Commit 58dd33e

Browse files
authored
Drop dead _update_categories function (#1194)
1 parent a1a45b7 commit 58dd33e

2 files changed

Lines changed: 2 additions & 53 deletions

File tree

‎inbox/mailsync/backends/imap/common.py‎

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
from sqlalchemy import bindparam, desc # type: ignore[import-untyped]
1818
from sqlalchemy.orm import Session # type: ignore[import-untyped]
1919
from sqlalchemy.orm.exc import NoResultFound # type: ignore[import-untyped]
20-
from sqlalchemy.sql.expression import func # type: ignore[import-untyped]
2120

2221
from inbox.contacts.processing import update_contacts_from_message
2322
from inbox.crispin import RawMessage
2423
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
2625
from inbox.models.backends.imap import ImapFolderInfo, ImapUid
2726
from inbox.models.category import Category
2827
from inbox.models.session import session_scope
@@ -162,15 +161,6 @@ def update_message_metadata(
162161
if old_categories or new_categories:
163162
message.updated_at = update_time
164163

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-
174164

175165
def update_metadata( # type: ignore[no-untyped-def]
176166
account_id, folder_id, folder_role, new_flags, session
@@ -367,44 +357,3 @@ def create_imap_message(
367357
)
368358

369359
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

‎tests/imap/test_update_metadata.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_generic_drafts_flag_constrained_by_folder(
7777
assert message.is_draft == (folder_role == "drafts")
7878

7979

80-
def test_update_categories_when_actionlog_entry_missing(
80+
def test_categories_follow_imap_labels_without_label_change(
8181
db, default_account, message, imapuid
8282
) -> None:
8383
message.categories_changes = True

0 commit comments

Comments
 (0)