WP Manifestindependent plugin directory
manifest / performance / cached-wpdb-queries

Cached WPDB Queries

Cached WordPress wpdb queries

★ 1stars
1.0.1latest · 5 years ago

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/petenelson/cached-wpdb-queries/archive/refs/heads/trunk.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

Cached WordPress wpdb queries

Specific queries in WordPress core are executed directly against the database (such as get_available_post_mime_types()) and currently do not have filters that allow bypassing the SQL query that is executed. On large installations with tens of thousands of records in the wp_posts table, some of these queries can run quite slow. This plugin allows for "caching" of the results of these queries via records in the options table to improve performance.

Note: Use this sparingly and only to cache wpdb queries that currently cannot be cached or bypassed by other means.

How it works:

  • Specific queries from core can be flagged for caching, such as: SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = 'attachment'
  • Each original query is configured with:
    • original The original wpdb query from WordPress core.
    • source_callback that is used to get the data to be cached.
    • expires in seconds for how long the results should be cached.
    • create_records_callback used to create records in the option table. This function is passed the results from the source callback.
    • updated The new query that will be used instead against the options table.

See the code in get-available-post-mime-types.php function for an example. Basically it is taking the distint post_mime_type records for attachments, creating records in the options table with specific prefixes, then running a wildcard starts-with query against the options table, rather than the wp_posts table, to get the results.

Releases

2 releases.

Tag
Published
1.0.1 latest
Nov 4, 2020 5 years ago
Nov 3, 2020 5 years ago

These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.