Making WordPress.org


Ignore:
Timestamp:
01/06/2026 01:01:00 AM (4 months ago)
Author:
dd32
Message:

Plugin Directory: Jobs: Zip Cleanup: Avoid OOM errors by being more specific in what we're querying here.

See #5636.

File:
1 edited

Legend:

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

    r13647 r14623  
    2929
    3030        $attachments = get_posts( [
     31            'fields'         => 'id=>parent',
    3132            'post_type'      => 'attachment',
    3233            'post_mime_type' => 'application/zip',
     
    3839                    'before' => self::KEEP_DAYS . ' days ago',
    3940                ]
    40             ]
     41            ],
     42
     43            // Don't prime caches, helps with some memory when we're not really using any of it.
     44            'update_post_meta_cache' => false,
     45            'update_post_term_cache' => false,
    4146        ] );
    4247
    43         foreach ( $attachments as $attachment ) {
    44             $plugin = get_post( $attachment->post_parent );
     48        foreach ( $attachments as $attachment_id => $plugin_id ) {
     49            $plugin = get_post( $plugin_id );
    4550
    4651            // If not a plugin upload, or something drastically is wrong..
    47             if ( ! $attachment->post_parent || ! $plugin || 'plugin' !== $plugin->post_type ) {
     52            if ( ! $plugin_id || ! $plugin || 'plugin' !== $plugin->post_type ) {
    4853                continue;
    4954            }
     
    6368            $plugin_last_touched_date = 0;
    6469            foreach ( [ 'plugin_closed_date', '_approved', '_publish', '_rejected' ] as $meta_field ) {
    65                 $meta_value = get_post_meta( $plugin->ID, $meta_field, true );
     70                $meta_value = get_post_meta( $plugin_id, $meta_field, true );
    6671                if ( ! $meta_value ) {
    6772                    continue;
     
    8590
    8691            // Cleanup ZIP-related metadata.
    87             delete_post_meta( $plugin->ID, '_submitted_zip_size' );
    88             delete_post_meta( $plugin->ID, '_submitted_zip_loc' );
     92            delete_post_meta( $plugin_id, '_submitted_zip_size' );
     93            delete_post_meta( $plugin_id, '_submitted_zip_loc' );
    8994
    9095            // Delete the file hash from the post.
    91             $file_on_disk = get_attached_file( $attachment );
     96            $file_on_disk = get_attached_file( $attachment_id );
    9297            if ( $file_on_disk && file_exists( $file_on_disk ) ) {
    9398                $file_hash = sha1_file( $file_on_disk );
     
    97102            }
    98103
    99             wp_delete_attachment( $attachment->ID, true );
     104            wp_delete_attachment( $attachment_id, true );
    100105        }
    101106    }
Note: See TracChangeset for help on using the changeset viewer.