-
Notifications
You must be signed in to change notification settings - Fork 66
Return number of records deleted #32
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
Comments
The current spec allows implementations to optimize the behavior of delete(), e.g. avoiding read-back of the records. It's unclear if that optimization is actually used in practice. https://www.w3.org/Bugs/Public/show_bug.cgi?id=22130 suggests allowing IDBObjectStore.clear(query) to take an optional query and have clear() be a fast-path, and have delete() yield a count. |
Should we be limiting this to just deletions? Perhaps we can make a generalized method to return all affected entries in a previous add, put, or delete operation? I am concerned that yielding a count for deletions would make it seem inconsistent with the other methods of manipulation that would not yield counts. |
Interesting thought.
|
FYI, |
We saw negligible performance impact from the change based on our perf tests. |
I'm surprised that is the case. Don't you guys just add an entry to an in-memory table when removing entries? And only once the transaction is committed write the deletion to LevelDB? Whereas if you need to return a count, you'd obviously need to go to LevelDB to read a count of the number of entries in the deleted range. That said, I'm really not particularly opinionated here. I'll just note that people tend to use whatever function meets their need and has the shortest name. So if there is a performance difference in the future, it's better to introduce |
The way we currently delete, we iterate over a union of our 'pending' changes and the current database entries, and either update our pending change or create a new pending change with the status of 'deleted'. So all we need to do (for our implementation) is count the number of items where we either created a new 'pending' entry, or if there was already a pending entry that wasn't marked as deleted. So we're basically adding an if statement and incrementing a counter. |
And you're fine with being locked into that implementation strategy? |
Maybe. I think a general affected_entries or rows_affected feature would be more powerful, so maybe somehow optionally enabling that on a per-transaction basis would be cool. I'm not sure how that would look though. |
We've talked (internally) about a smarter approach where a range delete is covered by a single record rather than iterating, which is one of the reasons we pushed back against this suggestion before. But we wanted to float the idea if other implementers were strongly in favor of it. |
I definitely don't feel strongly either way. But I would lean towards having an explicit delete-and-count function. Would be interesting to get feedback from the other IDB implementations. |
We would definitely not want this to be the default. |
We prefer that this is not the default behavior as well. |
Got it - not the default. Are there preferences between these approaches:
|
I don't have an opinion either way. 2 has fewer characters, but 1 is more expandable in the future if that matters. |
For 1, I suppose the real question is if we actually see ourselves expanding the As a side note, if the deletion transaction is indeed guaranteed, how would it be any different from first getting the count ( |
I'm very familiar with verbose APIs like what you're going for with #2 (Objective-C, Cocoa-style) and I don't think there's a place for them in a context like this. From an API naming perspective, "deleteWithCount" sounds much more like the function will also take a "count" argument. I was already thinking #1 was the way to go. A options object with "currently allows only one option" is not a problem. I wonder if "count:" is descriptive enough - It feels a little lightweight to me, though I don't have a better alternative ATM. |
Agreed, |
|
I'm not a fan of repeating "delete" in the option name. |
Requested enhancement: allow some means to determine how many records were deleted in an operation
The IDBObjectStore.delete(query) operation is specified to yield
undefined
. Getting the count would be useful.Imported from https://www.w3.org/Bugs/Public/show_bug.cgi?id=22130
The text was updated successfully, but these errors were encountered: