WordPress.org

Make WordPress Core

Changeset 891 in tests


Ignore:
Timestamp:
07/09/12 14:12:58 (3 years ago)
Author:
nacin
Message:

Request all open tickets from a Trac install at once.

This prevents repeated HTTP requests for individual tickets and
allows us to keep knownWPBug (or @ticket - see #102) in place for
tickets already closed, without any real performance penalty.
This is good for tracking and also in case a bug is reopened.

This shaved 30 seconds off the test suite run time for me.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/trac.php

    r883 r891  
    33class TracTickets { 
    44    /** 
    5      * Whenever a track ticket is checked to see if it's closed or not 
    6      * the results are stored here 
     5     * When open tickets for a Trac install is requested, the results are stored here. 
     6     * 
    77     * @var array 
    88     */ 
     
    1414     * @return bool|null true if the ticket is resolved, false if not resolved, null on error 
    1515     */ 
    16     static function isTracTicketClosed($trac_url, $ticket_id) { 
    17         $trac_url = rtrim($trac_url, '/'); 
    18         $url = "$trac_url/ticket/$ticket_id?format=tab"; 
    19         if ( array_key_exists( $url, self::$trac_ticket_cache ) ) { 
    20             return self::$trac_ticket_cache[$url]; 
     16    public static function isTracTicketClosed( $trac_url, $ticket_id ) { 
     17        if ( ! isset( self::$trac_ticket_cache[ $trac_url ] ) ) { 
     18            $tickets = file_get_contents( $trac_url . '/query?status=%21closed&format=csv&col=id' ); 
     19            $tickets = substr( $tickets, 2 ); // remove 'id' 
     20            $tickets = trim( $tickets ); 
     21            $tickets = explode( "\r\n", $tickets ); 
     22            self::$trac_ticket_cache[ $trac_url ] = $tickets; 
    2123        } 
    22         $ticket_tsv = file_get_contents($url); 
    23         if (false === $ticket_tsv) { 
    24             self::$trac_ticket_cache[$url] = null; 
    25             return self::$trac_ticket_cache[$url]; 
    26         } 
    27         $lines = explode("\n", $ticket_tsv, 2); 
    28         if (!is_array($lines) || count($lines) < 2) { 
    29             self::$trac_ticket_cache[$url] = null; 
    30             return self::$trac_ticket_cache[$url]; 
    31         } 
    32         $titles = str_getcsv( $lines[0], "\t" ); 
    33         $status_idx = array_search('status', $titles); 
    34         if (false === $status_idx) { 
    35             self::$trac_ticket_cache[$url] = null; 
    36             return self::$trac_ticket_cache[$url]; 
    37         } 
    38         $tabs = str_getcsv( $lines[1], "\t" ); 
    39         self::$trac_ticket_cache[$url] = ( 'closed' === $tabs[$status_idx] ); 
    40         return self::$trac_ticket_cache[$url]; 
     24 
     25        return ! in_array( $ticket_id, self::$trac_ticket_cache[ $trac_url ] ); 
    4126    } 
    4227} 
Note: See TracChangeset for help on using the changeset viewer.