Make WordPress Core

Changeset 572 in tests


Ignore:
Timestamp:
03/13/2012 10:24:08 PM (14 years ago)
Author:
kurtpayne
Message:

Cache results of isTracTicketClosed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testlib/base.php

    r566 r572  
    396396         */
    397397        function isTracTicketClosed($trac_url, $ticket_id) {
    398                 #TODO: cache it
     398                global $trac_ticket_cache;
     399                if ( !isset( $trac_ticket_cache ) || !is_array( $trac_ticket_cache ))
     400                        $trac_ticket_cache = array();
    399401                $trac_url = rtrim($trac_url, '/');
    400                 $ticket_tsv = file_get_contents("$trac_url/ticket/$ticket_id?format=tab");
     402                $url = "$trac_url/ticket/$ticket_id?format=tab";               
     403                if ( array_key_exists( $url, $trac_ticket_cache ) ) {
     404                        return $trac_ticket_cache[$url];
     405                }
     406                $ticket_tsv = file_get_contents($url);         
    401407                if (false === $ticket_tsv) {
    402                         return null;
     408                        $trac_ticket_cache[$url] = null;
     409                        return $trac_ticket_cache[$url];
    403410                }
    404411                $lines = explode("\n", $ticket_tsv, 2);
    405412                if (!is_array($lines) || count($lines) < 2) {
    406                         return null;
     413                        $trac_ticket_cache[$url] = null;
     414                        return $trac_ticket_cache[$url];
    407415                }
    408416                $titles = str_getcsv( $lines[0], "\t" );
    409417                $status_idx = array_search('status', $titles);
    410418                if (false === $status_idx) {
    411                         return null;
     419                        $trac_ticket_cache[$url] = null;
     420                        return $trac_ticket_cache[$url];
    412421                }
    413422                $tabs = str_getcsv( $lines[1], "\t" );
    414                 return 'closed' === $tabs[$status_idx];
     423                $trac_ticket_cache[$url] = ( 'closed' === $tabs[$status_idx] );
     424                return $trac_ticket_cache[$url];
    415425        }
    416426
Note: See TracChangeset for help on using the changeset viewer.