Deleting Data in callback will change total results #92

Closed
JasonHoffmann opened this Issue Dec 20, 2016 · 6 comments

Projects

None yet

2 participants

@JasonHoffmann
Contributor

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:

  • Allow the JS AJAX call to pass back a total_num_results number. If the function receives this parameter in the request, it will override whatever the function does. On the first step, the backend will grab the total_num_results and hand it off to React. All subsequent steps will work off of that original number, passing it back and forth.
  • Grab that number on first attempt and hold it in memory or in an option or somewhere where it can persist across multiple AJAX requests. Honestly not sure where it could go.

Thoughts?

@JasonHoffmann JasonHoffmann added this to the 0.9 MVP Launch milestone Dec 20, 2016
@zachwills
Collaborator

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.

@zachwills
Collaborator

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.

@JasonHoffmann
Contributor

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?

@zachwills
Collaborator

Passing it along to & from the client -> server as you suggested earlier sounds like it would work.

@JasonHoffmann
Contributor

Let me give that a shot, see how it works.

@JasonHoffmann
Contributor

Closed in #96. And it’s a biggie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment