Skip to content

Commit

Permalink
chunk deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
squeaky-pl committed Nov 7, 2024
1 parent aadad41 commit 859b3d1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions inbox/mailsync/backends/imap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from inbox.models.session import session_scope
from inbox.models.util import reconcile_message
from inbox.sqlalchemy_ext.util import get_db_api_cursor_with_query
from inbox.util.itert import chunk

log = get_logger()

Expand Down Expand Up @@ -285,17 +286,19 @@ def remove_deleted_uids(account_id: int, folder_id: int, uids: Iterable[int]) ->

for message_id, message_uids in uids_by_message_id.items():
with session_scope(account_id) as db_session:
db_session.query(ImapUid).filter(
ImapUid.account_id == account_id,
ImapUid.folder_id == folder_id,
ImapUid.msg_uid.in_(message_uids),
).with_hint(
ImapUid, "FORCE INDEX (ix_imapuid_account_id_folder_id_msg_uid_desc)"
).delete(
synchronize_session=False
)

print(message_id, len(message_uids))
for message_uid_batch in chunk(message_uids, 1000):
db_session.query(ImapUid).filter(
ImapUid.account_id == account_id,
ImapUid.folder_id == folder_id,
ImapUid.msg_uid.in_(message_uid_batch),
).with_hint(
ImapUid,
"FORCE INDEX (ix_imapuid_account_id_folder_id_msg_uid_desc)",
).delete(
synchronize_session=False
)
print("after delete")

deleted_uid_count += len(message_uids)

Expand Down

0 comments on commit 859b3d1

Please sign in to comment.