API for Batch Queries
Tanguy-Magnaudet opened this issue · 0 comments
Tanguy-Magnaudet commented
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