Making WordPress.org


Ignore:
Timestamp:
02/20/2024 06:11:47 AM (3 years ago)
Author:
dd32
Message:

Plugin Directory: Meta Sync: Cleanup the memory more frequently, optimize the get_terms() calls to avoid OOM issues.

Followup to [13223].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-meta-sync.php

    r13223 r13224  
    2626        function sync() {
    2727                $this->sync_downloads();
     28                Manager::clear_memory_heavy_variables();
     29
    2830                $this->sync_ratings();
     31                Manager::clear_memory_heavy_variables();
     32
    2933                $this->update_tested_up_to();
     34                Manager::clear_memory_heavy_variables();
     35
    3036                $this->cleanup_empty_terms();
    31 
    3237                Manager::clear_memory_heavy_variables();
    3338        }
    … …  
    202207         */
    203208        public function cleanup_empty_terms() {
     209                global $wpdb;
     210
    204211                $taxonomies = [
    205212                        'plugin_tags',
    … …  
    209216                ];
    210217                foreach ( $taxonomies as $taxonomy ) {
     218                        $term_ids = $wpdb->get_col( $wpdb->prepare(
     219                                "SELECT term_id FROM $wpdb->term_taxonomy WHERE taxonomy = %s AND count = 0",
     220                                $taxonomy
     221                        ) );
     222                        if ( ! $term_ids ) {
     223                                continue;
     224                        }
     225
    211226                        $terms = get_terms( array(
    212227                                'taxonomy'   => $taxonomy,
     228                                'include'    => $term_ids,
    213229                                'hide_empty' => false,
    214230                                'count'      => true,
Note: See TracChangeset for help on using the changeset viewer.