kinto icon indicating copy to clipboard operation
kinto copied to clipboard

Events for deletion of children ?

Open leplatrem opened this issue 6 years ago • 2 comments

Should we send ResourceChanged events for each children when we delete a parent?

For example: if I delete a bucket, it sends a delete event for every collection in the bucket, and an event for every record in each collection?

Should we do it if there are a million record?

Related #945 #1647

leplatrem avatar May 24 '18 13:05 leplatrem

I'm kind of tying myself into knots here. The problem I'm facing is that if you delete a bucket and then a collection from inside that bucket, the event listener for buckets deletes the quota record for the bucket, and then the quotas plugin emits a nonsensical quota record for the bucket (-1 records, -x size). If you do it the other way around, the quota record is correct, and then the event listener for the bucket deletes it. When I see this, I see a dependency on the bucket listener by the quotas plugin, and my view ends up depending on both of them.

Now, if the buckets event listener doesn't emit events for deleting its children, then you end up with something like the current quotas plugin. When a collection is deleted, it does a get_all to fetch the records that it "knows" will be deleted, and takes them into account, and it "knows" that it doesn't have to clean up its quota entries because they'll be deleted by the buckets/collections event listeners.

If the buckets plugin does emit events for deleting its children, then the quotas plugin gets both simpler and more complicated, because it no longer has to do a get_all to fetch records, but it has to accommodate the fact that when an event shows up for a deleted record, it may be a "cascade" from a deleted bucket that it already saw. I can't tell, but this might mean that there's still knowledge "baked in" to the quotas plugin that says what kind of objects are children of what other kinds of objects.

I don't love either of these approaches. I think if you care about record deletion, you shouldn't have to also listen to collection and bucket deletion. My feeling is that the most correct thing to do is to delete the children before deleting the parent, but that can't be made to work with the buckets event listener as it stands today (because it only happens after the bucket was deleted).

glasserc avatar May 24 '18 18:05 glasserc

This becomes an issue too for the history plugin. If deleted records via the plural endpoint are not tracked, then it's impossible to reconstruct a snapshot from the history log.

leplatrem avatar Feb 17 '21 10:02 leplatrem