Make deleting a project purge the cache #2849
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2418. This is a prerequisite for #2821.
The reason that the project wasn't being purged is because using the bulk deletion API via
request.db.query(...).delete()
never loads the deleted objects into the session, so when ourafter_flush
db hook fires,session.deleted
is empty.I thought an alternative might be hooking into the
after_bulk_delete
event, which receives adelete_context.matched_objects
, but this also only contains objects already in the session that have been deleted.The simplest thing we could do here is load everything that needs to be purged into the session (via
request.db.query(...).all()
and then delete them. Presumably doing so would make this a) a bit slower and b) require a bit more memory, but since deletion happens infrequently enough (and since the next thing we're doing is removing all these objects from the session) I figured this was OK, so that's what this PR does.I don't totally love this, because it requires us to remember to delete things differently if we want them to be purged from the cache, but I don't see any alternatives that don't involve making purging more manual than it already is.