-
Notifications
You must be signed in to change notification settings - Fork 12
Use passive_delete to handle LabelItem cascade
#1077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The way I understand this, Also, I wanted to understand this problem better (I don't think I fully grasped it before now), so I did some research, and I wonder - couldn't we just preemptively load the related children here to avoid them being loaded lazily while An alternative would be to collect the IDs of object to delete, and then just delete them in batches: for imap_uid_ids_batch in batched(ids_to_delete, 1000): # pseudo-code
for imap_uid in db_session.query(ImapUid).filter(ImapUid.id.in_(imap_uid_ids_batch)):
imap_uid.delete() |
|
@neob91-close Yes, the passive deletes depends on the database to cascade for deletes. For constraints in the database, the Inspecting the table confirms the constraint exists on As far as pre-emptively loading children: Yes, I think that would resolve the error. However, we're going to be loading uids for every entry in the folder when resyncing. The query explicitly loads only the ID and google message ID. Using passive deletes saves us from a bunch of loading and work. Collecting the IDs and deleting in batches afterward: Yes, that could work too. Would that essentially be https://github.com/closeio/sync-engine/pull/1063/files, just pulling the call to # Adapted to your pseudocode rather than common delete
for chunk in batched(ids_to_delete):
for imap_uid in db_session.query(ImapUid).filter(ImapUid.id.in_(chunk)):
imap_uid.delete()
imap_folder_info_entry.uidvalidity = uidvalidity
imap_folder_info_entry.highestmodseq = None
db_session.commit()The simplest solution overall is probably eager loading the label items. I'll give that a test. I'm still a little sceptical that we just call delete on the |
|
Eager loading collections isn't supported via
Essentially, joined loading for collections never works with I think passive deletes is potentially the smoothest solution. Looking into |
|
I appreciate the detailed investigation! The That said, I don't want to block this too much longer, I'm sure you have better things to do than discuss different options on this one issue, so if you're adamant about the |
| # We need to add labels to our imap uids so that the cascade delete on | ||
| # LabelItems is required. This would trigger a deletion during the yield_chunk | ||
| # query if any ORM level cascades are triggered. | ||
| imap_uids = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think we should add a sanity check assertion that checks the number of ImapUid currently stored in the database is what we expect it to be. Currently it looks to me like we trust initial_sync to add stuff to the database, but I'd rather tests weren't so trusting.
|
I think you may have run I run linting this way (I know, hacky and inefficient): ip-192-168-100-38:close-ui neob91$ cat ../sync-engine/lint
#!/bin/bash
docker compose run --rm app bash -c 'pip3 install -r requirements/requirements-lint.txt; ruff check --fix inbox tests; black inbox tests' |
|
I hope you don't mind me pushing to your branch, but I fixed the formatting and added a very simple test assertion. My only motivation here was to make your life easier (you should have a green mergeable PR when you come in). Let me know if I overstepped! |
I've been running it in the container, installed from the requirements. But I ran black then ruff. |
When triggering a resync for gmail, we attempt to delete any unmatched imap UID entries during the
yield_chunkiterations. If there is more than one chunk, then this query is still active in the session, and we get aCommands out of sync; you can't run this command nowerror.Using
passive_deletes=True, we can avoid lazy loading and deleting the associations in the ORM. We keep thecascade="all, delete-orphan"so that the ORM handles the deletion if we remove the label item from the association list.This is the other approach I was considering in: #1063