-
Notifications
You must be signed in to change notification settings - Fork 823
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
Add a size method to the Queue class #2018
Conversation
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.
LGTM.
Quick check: is there any benefit of testing a case where you add the same StorableRequest
to the queue multiple times, and seeing how .size()
deals with that scenario? I'm not sure what the expected behavior is in that scenario, so if it's not an "interesting" test case, feel free to ignore.
There's not currently any deduping, so it would report the total number of entries regardless of whether the underlying requests were the same (or not). |
e55bcd7
to
970ed19
Compare
@jeffposnick I force-pushed the changes we talked about in chat. Let me know if you have any comments on them. |
970ed19
to
ec49ecf
Compare
I understand that adding a single |
@bligny thanks for taking a look. Your suggestion is actually how I originally implemented it, but then I realized that a We could potentially add a The best solution (in my opinion) is unfortunately not available to us at the moment, and that's to use a multi-key index on our IDB object store, so we can have the entries sorted by So, given all this context, what do you think is the best option to support your use case? |
PR-Bot Size PluginChanged File Sizes
New FilesNo new files have been added. All File SizesView Table
Workbox Aggregate Size Plugin8.9KB gzip'ed (59% of limit) |
Also cc: @Fitzchev |
@philipwalton thanks for your quick reply. I do agree that the
The next question is what would be the best (most logical) default value for the optional I let you take the final decision, I'm already happy with the existing improvement :-) PS: Personal opinion: I'm a bit sceptical about the automatic purge (deletion of expired entries) which is done in your getAll(). I find dangerous to perform write operations inside a read-only (eg getX()) method. |
@philipwalton thanks a lot, it definitively covers my use case. Reading @bligny comment and looking at the "automatic purge" of expired items, it makes me think that it could be interesting to know that there are expired items left in the queue. What about having a global parameter automatic_purge = yes/no - if yes, keep the same behavior, if no rise an event workbox_expired_items so that the user can decide what to do with them (rise an alert, purge anyway...) |
Thanks everyone for the comments. I think for the moment I'm going to keep this PR as is. Once we can drop Edge 18 support, we can rework the data model to use multi-key indexes and add a standalone Also, once we get to the next major release we can re-evaluate whether or not it makes sense to have entries silently expire (or maybe change the default, but that would be a breaking change). At the moment, if you don't like the silent expire behavior, you can alway set the |
R: @jeffposnick
Fixes #2011
This PR adds a method to count the number of entries in the queue store for the given queue name.
UPDATE: Given #2011 (comment) and the fact that the initial changes in the PR didn't consider that a simple IndexedDB count operation wouldn't account for entries that have expired, I decided to just add a single
getAll()
method that returns an array of unexpired entries. Users who need a count can access that array's length.