You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following ACF fields would need to be modified:
// AdvancedCustomFields.php
// Add new bulk/fields/etc method
public function fields($fields)
{
// whereIn limits the fields down to just the keys we are looking for
// feed the same stuff into the Factory
return $this->post
->meta
->whereIn('meta_key', array_keys($fields))
->mapWithKeys(function($field) use ($fields)
{
$value = FieldFactory::make($field, $this->post, snake_case($fields[$field->meta_key]))->get();
return [$field->meta_key => $value];
});
}
And BasicField (at minimum):
// BasicField
// This bit is the tricky bit - we need to remove the query from fetchValue
// possibly into a seperate method (maybe performQuery)
public function fetchValue($field)
{
// $postMeta = $this->postMeta->where(
// $this->getKeyName(), $this->post->getKey()
// )->where('meta_key', $field)->first();
if (isset($postMeta->meta_value) and ! is_null($postMeta->meta_value)) {
$value = $postMeta->meta_value;
...
// remaining code is the same
Concerns
My major concern is I am missing something major - as to why the per field query is needed (the removed lines in BasicField).
Obviously regression is reasonably big too.
Thoughts before kicking off a PR? I'm extremely short on time (who isn't?) at the moment - so need to be careful how I allocate resources.
The text was updated successfully, but these errors were encountered:
The following is a working (but with possible regressions) snippet to reduce the query load of fetching many acf fields.
Summary
The overarching principal is:
select * from
wp_postmetawhere
post_idin ('106')
via$this->post->meta
This, from elementary testing, changes the query to 1 + N (1 for post + N per acf field) to 2 (1 for post + 1 for all meta).
Before:
After:
Code changes
The following ACF fields would need to be modified:
And BasicField (at minimum):
Concerns
My major concern is I am missing something major - as to why the per field query is needed (the removed lines in BasicField).
Obviously regression is reasonably big too.
Thoughts before kicking off a PR? I'm extremely short on time (who isn't?) at the moment - so need to be careful how I allocate resources.
The text was updated successfully, but these errors were encountered: