Plugin Directory

Changeset 525505


Ignore:
Timestamp:
03/31/2012 12:41:07 AM (14 years ago)
Author:
complex_ntrsctn
Message:

Added transient caching to comment counts so remote call isn't required every time we need to know how many comments are on an article, will sit on changes over the weekend to make sure I can't think of anything else that's needed and then will write release note and tag a release on Monday if we're good to release comment integration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ntrsctn-content-aggregator/trunk/ntrsctn-aggregator.php

    r525138 r525505  
    188188}
    189189
    190 function ntrsctn_comments_enabled($post) {
     190function ntrsctn_comments_enabled($post=null) {
    191191    $ntrsctn_remote_comments_on = get_option('ntrsctn_json_api_remote_comments_on', DEFAULT_AGGREGATOR_REMOTE_COMMENTS_ON);
    192192    if (!$ntrsctn_remote_comments_on) {
     
    199199    if (empty($comments_url) || empty($shortname)) {
    200200        return false;
     201    }
     202   
     203    if (empty($post)) {
     204        return true;
    201205    }
    202206   
     
    217221    $comments_url = trim(get_option('ntrsctn_comments_url', DEFAULT_NTRSCTN_COMMENTS_URL));
    218222    $shortname = get_option('ntrsctn_json_api_shortname', '');
    219    
    220     // @todo comments should always be close so this not necessary
    221     if (!comments_open()) {
    222         print "<h2>Comments Closed</h2>";
    223         return $comments;
    224     }
    225223   
    226224    if (!ntrsctn_comments_enabled($wp_query->post)) {
     
    249247            /* Hide the WordPress commenting form
    250248            /*****************************/
    251             #respond, #commentform, #addcomment, .entry-comments {
     249            #respond, #commentform, #addcomment, .entry-comments, .nocomments {
    252250                display: none;
    253251            }   
     
    265263    }
    266264   
    267     // @todo cache fetch number of comments from comment server
     265    $post_id = $wp_query->post->ID;
     266    $transient = 'ntrsctn_c_'.$post_id;
     267    $result = get_transient($transient);
     268    if ($result !== false) {
     269        return $result;
     270    }
    268271   
    269272    $comments_url = trim(get_option('ntrsctn_comments_url', DEFAULT_NTRSCTN_COMMENTS_URL));
     
    271274    $params = array(
    272275        'shortname' => $shortname,
    273         'post_id' => $wp_query->post->ID
     276        'post_id' => $post_id
    274277    );
    275278   
     
    282285    curl_close($ch);
    283286
    284     return $result > 0 ? $result : 0;
     287    $result = $result > 0 ? $result : 0;
     288    // cache the number of comments on this article for 60 seconds
     289    set_transient($transient, $result, 60);
     290    return $result;
    285291}
    286292
     
    304310
    305311// Add a filter to replace wordpress comments with ntrsctn comments
    306 // @todo add preference to use ntrsctn comments
    307 // @todo add preference to use ntrsctn comments if posted after time X
    308312$ntrsctn_remote_comments_on = get_option('ntrsctn_json_api_remote_comments_on', DEFAULT_AGGREGATOR_REMOTE_COMMENTS_ON);
    309313if ($ntrsctn_remote_comments_on) {
Note: See TracChangeset for help on using the changeset viewer.