PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
← All changes | inc/classes/class-imagify-custom-folders.php +50 -6 2.3.0 → trunk View file →
@@ -738,14 +738,35 @@
738 738 $files_from_scan[ $folder_id ][ $file_path ] = $placeholder;
739 739 }
740 740 }
741 741
742 - $placeholders = Imagify_DB::prepare_values_list( array_keys( $folders_by_placeholder ) );
743 742 $select_fields = "$files_key_esc, folder_id, path" . ( $optimization ? ', optimization_level, status' : '' );
744 743
745 - $results = $wpdb->get_results( "SELECT $select_fields FROM $files_table WHERE path IN ( $placeholders ) ORDER BY folder_id, $files_key_esc;", ARRAY_A ); // WPCS: unprepared SQL ok.
744 + $results = [];
746 745
746 + foreach ( Imagify_DB::chunk_in_values( array_keys( $folders_by_placeholder ) ) as $placeholders_chunk ) {
747 + $placeholders = Imagify_DB::prepare_values_list( $placeholders_chunk );
748 + $chunk_results = $wpdb->get_results( "SELECT $select_fields FROM $files_table WHERE path IN ( $placeholders );", ARRAY_A ); // WPCS: unprepared SQL ok.
749 +
750 + if ( $chunk_results ) {
751 + $results = array_merge( $results, $chunk_results );
752 + }
753 + }
754 +
747 755 if ( $results ) {
756 + // Re-apply the ordering that was previously done in SQL (`ORDER BY folder_id, $files_key_esc`).
757 + usort(
758 + $results,
759 + function ( $a, $b ) use ( $files_key_esc ) {
760 + if ( $a['folder_id'] !== $b['folder_id'] ) {
761 + return $a['folder_id'] <=> $b['folder_id'];
762 + }
763 + return $a[ $files_key_esc ] <=> $b[ $files_key_esc ];
764 + }
765 + );
766 + }
767 +
768 + if ( $results ) {
748 769 // Damn...
749 770 $wpdb->flush();
750 771
751 772 foreach ( $results as $i => $row_fields ) {
@@ -903,15 +924,31 @@
903 924 $files_table = $files_db->get_table_name();
904 925 $files_key = $files_db->get_primary_key();
905 926 $files_key_esc = esc_sql( $files_key );
906 927 $file_ids = wp_list_pluck( $files, $files_key );
907 - $file_ids = Imagify_DB::prepare_values_list( $file_ids );
908 - $results = $wpdb->get_results( "SELECT * FROM $files_table WHERE $files_key IN ( $file_ids ) ORDER BY $files_key_esc;", ARRAY_A ); // WPCS: unprepared SQL ok.
928 + $results = [];
909 929
930 + foreach ( Imagify_DB::chunk_in_values( $file_ids ) as $file_ids_chunk ) {
931 + $file_ids_in = Imagify_DB::prepare_values_list( $file_ids_chunk );
932 + $chunk_results = $wpdb->get_results( "SELECT * FROM $files_table WHERE $files_key IN ( $file_ids_in );", ARRAY_A ); // WPCS: unprepared SQL ok.
933 +
934 + if ( $chunk_results ) {
935 + $results = array_merge( $results, $chunk_results );
936 + }
937 + }
938 +
910 939 if ( ! $results ) {
911 940 return;
912 941 }
913 942
943 + // Re-apply the ordering that was previously done in SQL (`ORDER BY $files_key_esc`).
944 + usort(
945 + $results,
946 + function ( $a, $b ) use ( $files_key_esc ) {
947 + return $a[ $files_key_esc ] <=> $b[ $files_key_esc ];
948 + }
949 + );
950 +
914 951 // Caching the folders will prevent unecessary SQL queries in Imagify_Custom_Folders::refresh_file().
915 952 foreach ( $folders as $folder_id => $folder ) {
916 953 wp_cache_set( 'custom_folder_' . $folder_id, $folder, 'imagify' );
917 954 }
@@ -995,12 +1032,19 @@
995 1032 $folders_table = $folders_db->get_table_name();
996 1033 $folders_key = $folders_db->get_primary_key();
997 1034
998 1035 $selected_paths = (array) $selected_paths;
999 - $selected_in = Imagify_DB::prepare_values_list( $selected_paths );
1036 + $folders = [];
1000 1037
1001 1038 // Get folders that already are in the DB.
1002 - $folders = $wpdb->get_results( "SELECT * FROM $folders_table WHERE path IN ( $selected_in );", ARRAY_A ); // WPCS: unprepared SQL ok.
1039 + foreach ( Imagify_DB::chunk_in_values( $selected_paths ) as $selected_paths_chunk ) {
1040 + $selected_in = Imagify_DB::prepare_values_list( $selected_paths_chunk );
1041 + $chunk_folders = $wpdb->get_results( "SELECT * FROM $folders_table WHERE path IN ( $selected_in );", ARRAY_A ); // WPCS: unprepared SQL ok.
1042 +
1043 + if ( $chunk_folders ) {
1044 + $folders = array_merge( $folders, $chunk_folders );
1045 + }
1046 + }
1003 1047
1004 1048 if ( ! $folders ) {
1005 1049 return $selected_paths;
1006 1050 }