Open nobleclem opened 6 years ago
For anyone who has a similar issue and this hasn't been resolved this is my current "fix":
add_filter( 'pods_data_pre_select_params', function( $params ){
global $wpdb;
if( ($params['table'] == $wpdb->terms) && isset( $params['join']['wpml_translations'] ) && isset( $params['join']['wpml_languages'] ) ) {
if( $params['select'] == '*, `t`.`term_id` AS `pod_item_id`' ) {
$newStars = array(
'`t`.*'
);
foreach( $params['join'] as $key => $val ) {
if( strpos( $key, 'wpml_' ) === false ) {
$newStars[] = "`{$key}`.*";
}
}
$params['select'] = str_replace(
'*,', implode( ', ', $newStars ) .', ', $params['select']
);
}
}
return $params;
});
@nobleclem Can you share the adjusted SQL after implementing your filter? Clever solution, btw.
sure its pretty simple change though....
SELECT DISTINCT
'`t`.*, `tt`.*, `tr`.*, `t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`'
FROM `wp_terms` AS `t`
LEFT JOIN `wp_term_taxonomy` AS `tt`
ON `tt`.`term_id` = `t`.`term_id`
LEFT JOIN `wp_term_relationships` AS `tr`
ON `tr`.`term_taxonomy_id` = `tt`.`term_taxonomy_id`
LEFT JOIN `wp_icl_translations` AS `wpml_translations`
ON `wpml_translations`.`element_id` = `tt`.`term_taxonomy_id`
AND `wpml_translations`.`element_type` = 'tax_category'
AND `wpml_translations`.`language_code` = 'en'
LEFT JOIN `wp_icl_languages` AS `wpml_languages`
ON `wpml_languages`.`code` = `wpml_translations`.`language_code`
AND `wpml_languages`.`active` = 1
WHERE ( ( `t`.`term_id` = 24610
OR `t`.`term_id` = 24611
OR `t`.`term_id` = 24613
OR `t`.`term_id` = 24614
OR `t`.`term_id` = 24617
OR `t`.`term_id` = 24615
OR `t`.`term_id` = 2
OR `t`.`term_id` = 24616 )
AND ( `tt`.`taxonomy` = "category" )
AND ( `wpml_languages`.`code` IS NOT NULL ) )
Also I encountered an issue with the filter. Sometimes the value passed is an array and sometimes its an object. So the modified filter is this as I didn't want to change the data type and was in a hurry to fix at the time:
add_filter( 'pods_data_pre_select_params', function( $params ){
global $wpdb;
if( is_object( $params ) ) {
if( ($params->table == $wpdb->terms) && isset( $params->join['wpml_translations'] ) && isset( $params->join['wpml_languages'] ) ) {
if( $params->select == '*, `t`.`term_id` AS `pod_item_id`' ) {
$newStars = array(
'`t`.*'
);
foreach( $params->join as $key => $val ) {
if( strpos( $key, 'wpml_' ) === false ) {
$newStars[] = "`{$key}`.*";
}
}
$params->select = str_replace(
'*,', implode( ', ', $newStars ) .', ', $params['select']
);
}
}
}
else if( is_array( $params ) ) {
if( ($params['table'] == $wpdb->terms) && isset( $params['join']['wpml_translations'] ) && isset( $params['join']['wpml_languages'] ) ) {
if( $params['select'] == '*, `t`.`term_id` AS `pod_item_id`' ) {
$newStars = array(
'`t`.*'
);
foreach( $params['join'] as $key => $val ) {
if( strpos( $key, 'wpml_' ) === false ) {
$newStars[] = "`{$key}`.*";
}
}
$params['select'] = str_replace(
'*,', implode( ', ', $newStars ) .', ', $params['select']
);
}
}
}
return $params;
});
I might revisit later and see about reducing the duplicate code just for the data type diff.
@sc0ttkclark anything we can get from that?
Issue Overview
Right now I have a site with ~12k posts, 20 categories, & 5 languages. We encountered a problem where an Editor edited a post associated with 8 categories and of those categories were associated to nearly all of the posts. This edit caused an out of memory issue preventing the post from being edited. After a bunch of digging I came across a query from Pods that generated a result set of 46k rows.
This query was generated from classes/Pods.php
field( 'category' )
on Line 1285That query in addition to its large result set also includes data from all 5 tables which I don't believe is necessary.
Possible Solution
Not knowing exactly what is done with this data afterwords it seems at a minimum the following change should be made: classes/Pods.php field() on Line 1286 update select statement to
but if only data from the terms table is used then ideally
The latter solution is more ideal as instead of in my case 46k rows I will only get 8.
WordPress Environment