Site logo

Archived topic

gp-premium is skipping the cache

1 reply · Started by Colin on June 4, 2021

Viewing posts 1–2 of 2

Would it be possible for the team to implement a transient lookup around the generate_premium_do_elements() inner get_posts function.

The query runs on every single page and is a wasted query. I have an object cache and because the plugin is directly calling get_post it'll never cache the options for the plugin.

The area in question is specifically at line 56 in gp-premium/elements/elements.php

$posts = get_posts( $args );
	foreach ( $posts as $post_id ) {
		$post_id = apply_filters( 'generate_element_post_id', $post_id );
		$type = get_post_meta( $post_id, '_generate_element_type', true );

If you implement the get_transient, an example here: https://wordpress.stackexchange.com/questions/162703/cache-get-posts/162707

Then only clear the transient when a change is made in the admin panel. That'll be one less query required on every single page load.

Hi Colin,

Using transients can be tricky, as some caching plugins can conflict with them.

However, it would definitely be nice if it was cached, even if it is just a single query. Perhaps using WP_Query() would be better than get_posts(). I'll take a closer look and try to come up with a solution.

Thanks!

Tom

This archived topic is closed to new replies.