Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

API for Batch Queries #1260

Open
Tanguy-Magnaudet opened this issue Oct 24, 2024 · 0 comments
Open

API for Batch Queries #1260

Tanguy-Magnaudet opened this issue Oct 24, 2024 · 0 comments

Comments

@Tanguy-Magnaudet
Copy link

Version

  • Carbon Fields: 3.6
  • WordPress: 6.4+
  • PHP: 8.0+

Expected Behavior

Add support for batch queries to optimize database performance when fetching multiple fields. Currently, each carbon_get_post_meta() call results in a separate database query, which is not ideal when you want to get a bunch of fields, store them in an array then display them into a page.

Expected functionality:

  • Ability to batch multiple field requests into a single query
  • Support for complex fields in batch operations

Expected API :

$fields = carbon_get_batch_post_meta($id, ['field_1', 'field_2', 'field_3']);
/* 
[
  'field_1' => 'formated_field_1_value',
  'field_2' => 'formated_field_2_value',
  'field_3' => 'formated_field_3_value',
]
*/

Actual Behavior

Currently, each field fetch requires a separate database call, which, on a very large website with a lot of fields, increase drastically I/O calls for no real reasons.

$title = carbon_get_post_meta($post_id, 'crb_title');       // 1 query
$description = carbon_get_post_meta($post_id, 'crb_desc');  // 1 query
$image = carbon_get_post_meta($post_id, 'crb_image');       // 1 query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant