starter-theme icon indicating copy to clipboard operation
starter-theme copied to clipboard

Performance issues /w ACF

Open raptor235 opened this issue 7 years ago • 2 comments

Hey guys, we're inheriting a project which was built on timber and are running into quite the mess in terms of performance.

On every page load timber Term class is creating over 2000 queries... I need to understand how the term class is supposed to work and how I could fix this issue...

The site is using ACF and when the Term class gets loaded it riggers

$custom = $this->get_term_meta( $term->term_id );

which then applies filters

$customs = apply_filters( 'timber_term_get_meta', $customs, $tid, $this );

which finally loads this monstrosity

public function term_get_meta( $fields, $term_id, $term ) {
		$searcher = $term->taxonomy . '_' . $term->ID; // save to a specific category
		$fds = get_fields( $searcher );
		if ( is_array( $fds ) ) {
			foreach ( $fds as $key => $value ) {
				$key = preg_replace( '/_/', '', $key, 1 );
				$key = str_replace( $searcher, '', $key );
				$key = preg_replace( '/_/', '', $key, 1 );
				$field = get_field( $key, $searcher );
				$fields[ $key ] = $field;
			}
			$fields = array_merge( $fields, $fds );
		}
		return $fields;
	}

On 35 terms in the system this creates 2000+ queries that run on EVERY single page load... is this normal for this starter theme?

Shouldn't any form of caching be implemented here to prevent this from happening on every single page load?

Any thoughts on work around of this?

raptor235 avatar Jan 03 '18 16:01 raptor235

Yikes! Thanks for this info @raptor235 — what version of Timber are you using?

jarednova avatar Jan 03 '18 23:01 jarednova

@jarednova Site was built with 1.1.7.1 I just upgraded to the latest version and same issue.

Actually nm just saw that was the latest version.. so ya... thoughts on how to fix this? I'm assuming that the more terms get added the more the number of queries will grow. It seems to be tied to a specific taxonomy. If I delete all the terms in that taxonomy the queries get reduced back to normal.

raptor235 avatar Jan 04 '18 01:01 raptor235

Closing this as outdated since 2.0 has landed

Levdbas avatar Nov 23 '23 09:11 Levdbas