Skip to content

Improve the update asset parent paths functionality for better performance #1027

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

aatanasov-cloudinary
Copy link
Collaborator

@aatanasov-cloudinary aatanasov-cloudinary commented Apr 8, 2025

Improving the update asset paths functionality to deliver better performance on the front-end and when performing WP Rest API requests.

Approach

  • The update and activate asset paths logic was split into two separate methods.
  • The process of updating the asset parent paths happens in these cases:
    • In the WordPress dashboard and the request is not REST API.
    • Using a cron (once a day). This covers manually uploaded plugins/themes.
  • The update process happens before the active one to ensure the activated asset parents are up to date.

QA notes

  • Ensure you have the WP Query Monitor plugin installed.
  • Ensure the Enable additional asset syncing setting is enabled and there are some plugins/themes activated. (screenshot attached below)
  • Go to the WordPress dashboard, and in the WP Query Monitor, filter by Plugin: cloudinary_wordpress and Caller: update_meta_cache(). (screenshot attached below)
  • While you're on the dashboard, there should be update_meta_cache queries that come from Cloudinary\Assets->update_asset_paths() as shown in the screenshot below.
  • Go to the Front-end, update_meta_cache from Cloudinary\Assets->update_asset_paths() shouldn't appear.
  • Testing Utils::is_rest_api() can happen by using a REST API request as this one wp-json/wp/v2/posts/?_envelope&_wpnonce=<nonce> -- the nonce can be got from wp-admin/admin-ajax.php?action=rest-nonce -- more info here.

Enabled asset syncing
asset-syncing

Postmeta queries
postmeta-queries-update

@aatanasov-cloudinary aatanasov-cloudinary marked this pull request as ready for review April 8, 2025 08:49
Copy link
Collaborator

@tharsheblows tharsheblows left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants