Experiment: Populate NCC Table Just Before Conversion #40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an incomplete experiment of an approach designed to avoid two potentially slow queries:
The (near) duplication of the posts table when the plugin is activated (https://github.com/Automattic/newspack-content-converter/blob/master/lib/class-installer.php#L164-L197), which could run very long for sites with a large number of posts.
OFFSET/LIMIT queries to retrieve the next batch (https://github.com/Automattic/newspack-content-converter/blob/master/lib/class-conversionprocessor.php#L561). These will run slowly as the OFFSET number grows.
The approach here is definitely incomplete — I didn't really dig in to the retry logic, and some of the batch tracking logic will need to be adjusted. This is just meant to be a conversation starter, to see if this alternate approach is viable and if it could potentially bring some significant performance improvements.
There are basically three new things going on here:
Don't create
ncc_wp_posts
on activation. At the beginning of each conversion operation, create it if it doesn't exist.When building the current batch, retrieve the IDs directly from the Posts table. Instead of using an
OFFSET
, use a combination ofID > n
andLIMIT
, which should be dramatically more performant.Populate
ncc_wp_posts
with the current batch immediately before processing. This table therefore becomes a true representation of the posts that have been converted, and it grows as the plugin does its work.