Came across a pretty big bug. If you are deleting some data in your callback function (wp_delete_post for instance), then the total_num_results number becomes a moving target, decreasing each time, and screwing up the progress bar and total number of steps. We need to grab the total_num_results once and then keep it there throughout the process.
I can think of two ways of doing this:
Ah- good find!
Do we care about the ability to dynamically process new items if they are created while a batch is running? Lets say we are processing a comment deletion or something and there are lots of new comments being added while it is run. Should the user have to manually rerun the batch to get those new comments? Or should the batch continue processing until they are all handled?
If we update it to store the initially found number of results and process from there, we eliminate the ability to handle the above scenario. Another scenario that wouldn't be possible might be a batch that goes through items and creates new ones until a certain condition is met.
What if we (somehow) kept track of the number of deleted items and added that number to the amount of found results each time a new step in a running batch is started? That should keep the progress bar up to date as well as prevent deleting items from breaking the batch.
Another idea: we store the initial found records and check the total found records each time a new step is run (which is what currently happens). If there are more, we update the total found records to match the new amount. If there are less, we continue to reference the previously stored total amount of records.
I think that would handle the case where new items are being added as well as if items get deleted.
Good call. Might as well try to head off edge cases where we can. The question is, where can we store it that it persists from request to request, but doesn’t require extra DB queries? A query var?
Passing it along to & from the client -> server as you suggested earlier sounds like it would work.
Let me give that a shot, see how it works.
Closed in #96. And it’s a biggie.