WordPress.org

Plugin Directory

Changeset 532240 for feedwordpress


Ignore:
Timestamp:
04/17/12 11:29:39 (5 years ago)
Author:
radgeek
Message:

Memory usage / Reduce the number of SyndicatedLink objects we are loading up with every pageload, on updates, etc. SIDE EFFECT: feedwordpress_update_feeds filters must be revised to work with an array of numeric IDs, not an array of SyndicatedLink objects

Location:
feedwordpress/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • feedwordpress/trunk/feeds-page.php

    r522283 r532240  
    830830                $ofc = $fwp_credentials; 
    831831                $fwp_credentials = $credentials; // Set 
    832                 $pie = FeedWordPress::fetch($f); 
     832                $pie = FeedWordPress::fetch($f, array("cache" => false)); 
    833833                $fwp_credentials = $ofc; // Re-Set 
    834834                 
  • feedwordpress/trunk/feedwordpie.class.php

    r455025 r532240  
    11<?php 
    2 global $fwp_oLinks; 
    3  
    42class FeedWordPie extends SimplePie { 
    53    var $subscription = NULL; 
     
    108 
    119            // Get URL with relevant parameters attached. 
     10            // Credentials will be handled further down. 
    1211            $new_url = $url->uri(array('add_params' => true)); 
    13  
    14             // Keep for access elsewhere. God this sucks. 
    15             if (!is_array($fwp_oLinks)) : 
    16                 $fwp_oLinks = array(); 
    17             endif; 
    1812             
    19             // Store data for later retrieval. 
    20             # $this->subscription = $url; 
    21             $fwp_oLinks[$new_url] = $url; 
     13            // Store for reference. 
     14            $this->subscription = $url->id(); 
    2215             
     16            // Pass it along down the line. 
    2317            $url = $new_url; 
    2418             
     
    2620            $this->subscription = NULL; 
    2721        endif; 
    28  
     22         
    2923        // OK, let's go. 
    3024        return parent::set_feed_url($url); 
  • feedwordpress/trunk/feedwordpress.php

    r524065 r532240  
    394394function the_syndication_feed_id ($id = NULL) { echo get_syndication_feed_id($id); } 
    395395 
    396 $feedwordpress_linkcache =  array (); // only load links from database once 
    397396function get_syndication_feed_object ($id = NULL) { 
    398     global $feedwordpress_linkcache; 
    399  
    400     $link = NULL; 
    401  
     397    global $feedwordpress; 
     398     
    402399    $feed_id = get_syndication_feed_id($id); 
    403     if (strlen($feed_id) > 0): 
    404         if (isset($feedwordpress_linkcache[$feed_id])) : 
    405             $link = $feedwordpress_linkcache[$feed_id]; 
    406         else : 
    407             $link = new SyndicatedLink($feed_id); 
    408             $feedwordpress_linkcache[$feed_id] = $link; 
    409         endif; 
    410     endif; 
    411     return $link; 
    412 } 
     400    return $feedwordpress->subscription($feed_id); 
     401} /* function get_syndication_feed_object() */ 
    413402 
    414403function get_feed_meta ($key, $id = NULL) { 
     
    420409    endif; 
    421410    return $ret; 
    422 } /* get_feed_meta() */ 
     411} /* function get_feed_meta() */ 
    423412 
    424413function get_syndication_permalink ($id = NULL) { 
     
    899888 
    900889    var $feeds = NULL; 
    901  
     890    var $feedurls = NULL; 
    902891    var $httpauth = NULL; 
     892     
    903893    # function FeedWordPress (): Contructor; retrieve a list of feeds  
    904894    function FeedWordPress () { 
    905895        $this->feeds = array (); 
     896        $this->feedurls  = array(); 
    906897        $links = FeedWordPress::syndicated_links(); 
    907898        if ($links): foreach ($links as $link): 
    908             $this->feeds[] = new SyndicatedLink($link); 
     899            $id = intval($link->link_id); 
     900            $url = $link->link_rss; 
     901             
     902            // Store for later reference. 
     903            $this->feeds[$id] = $id; 
     904            if (strlen($url) > 0) : 
     905                $this->feedurls[$url] = $id; 
     906            endif; 
    909907        endforeach; endif; 
    910          
     908 
    911909        $this->httpauth = new FeedWordPressHTTPAuthenticator; 
    912910    } // FeedWordPress::FeedWordPress () 
    913911 
     912    function subscribed ($id) { 
     913        return (isset($this->feedurls[$id]) or isset($this->feeds[$id])); 
     914    } /* FeedWordPress::subscribed () */ 
     915     
     916    function subscription ($which) { 
     917        $sub = NULL; 
     918         
     919        if (is_string($which) and isset($this->feedurls[$which])) : 
     920            $which = $this->feedurls[$which]; 
     921        endif; 
     922         
     923        if (isset($this->feeds[$which])) : 
     924            $sub = $this->feeds[$which]; 
     925        endif; 
     926         
     927        // Load 'er up if you haven't already. 
     928        if (!is_null($sub) and !($sub InstanceOf SyndicatedLink)) : 
     929            $link = new SyndicatedLink($sub); 
     930            $this->feeds[$which] = $link; 
     931            $sub = $link; 
     932        endif; 
     933         
     934        return $sub; 
     935    } /* FeedWordPress::subscriptions () */ 
     936     
    914937    # function update (): polls for updates on one or more Contributor feeds 
    915938    # 
     
    9881011         
    9891012        // Randomize order for load balancing purposes 
    990         $feed_set = $this->feeds; 
     1013        $feed_set = array_keys($this->feeds); 
    9911014        shuffle($feed_set); 
    9921015 
     
    10031026 
    10041027        $feed_set = apply_filters('feedwordpress_update_feeds', $feed_set, $uri); 
    1005  
     1028         
     1029     
    10061030        // Loop through and check for new posts 
    10071031        $delta = NULL; $remaining = $max_polls; 
    1008         foreach ($feed_set as $feed) : 
     1032        foreach ($feed_set as $feed_id) : 
     1033 
     1034            $feed = $this->subscription($feed_id); 
    10091035 
    10101036            // Has this process overstayed its welcome? 
     
    16221648        $feed->set_parser_class($parser_class); 
    16231649        $feed->force_feed($force_feed); 
    1624         $feed->set_cache_duration(FeedWordPress::cache_duration()); 
     1650        $feed->set_cache_duration(FeedWordPress::cache_duration($params)); 
    16251651        $feed->init(); 
    16261652        $feed->handle_content_type(); 
     
    16591685    } /* FeedWordPress::clear_cache () */ 
    16601686 
    1661     function cache_duration () { 
     1687    function cache_duration ($params = array()) { 
     1688        $params = wp_parse_args($params, array( 
     1689        "cache" => true, 
     1690        )); 
     1691         
    16621692        $duration = NULL; 
    1663         if (defined('FEEDWORDPRESS_CACHE_AGE')) : 
     1693        if (!$params['cache']) : 
     1694            $duration = 0; 
     1695        elseif (defined('FEEDWORDPRESS_CACHE_AGE')) : 
    16641696            $duration = FEEDWORDPRESS_CACHE_AGE; 
    16651697        endif; 
  • feedwordpress/trunk/feedwordpress_file.class.php

    r524066 r532240  
    88     
    99    function __construct ($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) { 
    10         global $fwp_oLinks; 
     10        global $feedwordpress; 
    1111        global $wp_version; 
    1212 
    1313        $source = NULL; 
    14         if (isset($fwp_oLinks[$url])) : 
    15             $source = $fwp_oLinks[$url]; 
     14        if ($feedwordpress->subscribed($url)) : 
     15            $source = $feedwordpress->subscription($url); 
    1616        endif; 
    1717         
  • feedwordpress/trunk/syndicatedlink.class.php

    r455025 r532240  
    165165    } /* SyndicatedLink::found () */ 
    166166 
     167    function id () { 
     168        return (is_object($this->link) ? $this->link->link_id : NULL); 
     169    } 
     170     
    167171    function stale () { 
    168172        global $feedwordpress; 
Note: See TracChangeset for help on using the changeset viewer.