• Hi,

    I encountered an issue with the “Alle Zählmarken überprüfen” (Check all pixels) function when having a large number of posts with assigned pixels.

    The Problem:

    When clicking “Alle Zählmarken überprüfen” in the METIS settings, the function would time out or fail silently when there are many pixels to check (in my case, several hundred). The function check_all_pixels() in classes/services.php sends ALL pixel IDs to the T.O.M. API in a single request, which causes timeouts and potential rate limiting issues.

    The Solution:

    I modified the check_all_pixels() function to process pixels in batches of 50 instead of all at once. Here’s the fix in classes/services.php:

    public static function check_all_pixels( int $batch_size = 50 ): bool {
        $pixel_for_check = DB_Pixels::get_all_pixels();
    
        if ( empty( $pixel_for_check ) ) {
            return false;
        }
    
        $all_public_ids = array_column( $pixel_for_check, 'public_identification_id' );
        $total_pixels = count( $all_public_ids );
        $success_count = 0;
    
        // Process in batches
        for ( $offset = 0; $offset < $total_pixels; $offset += $batch_size ) {
            $batch = array_slice( $all_public_ids, $offset, $batch_size );
    
            $result = Tom_Pixels::check_pixel_state( $batch );
    
            if ( $result && is_array( $result ) && count( $result ) ) {
                foreach ( $result as $pixel ) {
                    self::update_pixel_data_from_api( $pixel );
                    $success_count++;
                }
            }
    
            // Small pause between batches to avoid API overload
            if ( $offset + $batch_size < $total_pixels ) {
                usleep( 100000 ); // 100ms pause
            }
        }
    
        return $success_count > 0;
    }
    

    What this does:

    • Splits the pixel list into batches of 50 (configurable via parameter)
    • Processes each batch separately with a 100ms pause between requests
    • Prevents API timeouts and rate limiting
    • Works reliably even with thousands of pixels

    Hope this helps others experiencing the same issue!

You must be logged in to reply to this topic.