-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Site Editor: Templates Reconciliation Performance #25868
Description
In #25739 we merged an update to the templates handling that could affect the Site Editor performance on sites with many templates and template parts.
(cc @epiqueras who worked on this and might have a deeper knowledge of the whole logic.)
Template Reconciliation
Templates (and template parts) can be both provided by the theme as HTML files, or by the site as wp_template (and wp_template_part) posts.
Since there isn't a single source of truth, they need to be reconciled every now and then.
When the reconciliation happens:
- If the template is a post with status
publish(meaning: it has been modified and saved by the user), we don't need to reconcile. - If the template is a post with status
auto-draft(meaning: it is a direct copy from the original template file), we compare it with the template file, check if the content has been changed, and update the template post if needed. - If the template file hasn't been stored as post yet: insert a new post with status
auto-draftusing the template file as content.
This reconciliation happens by filtering rest_wp_template_query (and rest_wp_template_part_query), which runs on any REST request on wp_template (and wp_template_part).
Before #25739, we only reconciled the requested template or template part.
Now, we reconcile all templates and template parts.
Audit
If the site has a lot of templates, this might become very performance intensive.
Let's check what kind of performance impact this have, and address it as much as we can.
Chances are that we don't really need to reconcile all templates so often.