Making WordPress.org


Ignore:
Timestamp:
09/05/2016 07:59:47 PM (8 years ago)
Author:
iandunn
Message:

WordCamp Budgets Dashboard: Check for paid invoices in batches

The previous limit of 100 was too small, because we currently have 150 pending invoices, and the latter third weren't being checked.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/sponsor-invoices-dashboard.php

    r3807 r3968  
    249249
    250250    $table_name = get_index_table_name();
    251 
    252     /*
    253      * This query is limited at 100 rows to avoid requesting too much data from QBO. In most cases it shouldn't be
    254      * a problem, but it's possible that at some point the number of pending invoices will exceed the limit, and
    255      * we'll need to refactor this to update them in batches.
    256      */
     251    $paid_invoices = array();
     252
    257253    $sent_invoices = $wpdb->get_results( "
    258254        SELECT blog_id, invoice_id, qbo_invoice_id
    259255        FROM $table_name
    260256        WHERE status = 'wcbsi_approved'
    261         LIMIT 100
     257        LIMIT 1000
    262258    " );
    263259
    264     $paid_invoices = \WordCamp_QBO_Client::get_paid_invoices(
    265         wp_list_pluck( $sent_invoices, 'qbo_invoice_id' )
    266     );
     260    // Batch requests in order to avoid request size limits imposed by QuickBooks, nginx, etc
     261    $qbo_invoice_ids = wp_list_pluck( $sent_invoices, 'qbo_invoice_id' );
     262    $qbo_invoice_ids = array_chunk( $qbo_invoice_ids, 20 );
     263
     264    foreach( $qbo_invoice_ids as $batch ) {
     265        $paid_invoices = array_merge(
     266            $paid_invoices,
     267            \WordCamp_QBO_Client::get_paid_invoices( $batch )
     268        );
     269
     270        usleep( 300000 );   // Avoid hitting the API too frequently
     271    }
    267272
    268273    mark_invoices_as_paid( $sent_invoices, $paid_invoices );
Note: See TracChangeset for help on using the changeset viewer.