Saturday, January 5, 2013

Wordpress JetPack Carousel Comments Cause Load

While the Wordpress Jetpack Carousel looks awesome, it just killed my site. Digging into things, the issue was caused by changing formerly static cached pages into pages that made AJAX calls to PHP to see if there were comments available.

I posted on the issues forum for Wordpress and didn't meet with much success. You can see the one response I got here.

 The AJAX calls are actually generated by javascript from the file ./wp-content/plugins/jetpack/modules/carousel/jetpack-carousel.js. The easiest way to disable comments from causing server load is to edit the file by finding the lines:
                getComments: function( args ) {
                        if ( 'object' != typeof args )
and change them to
                getComments: function( args ) {
                    return;
                        if ( 'object' != typeof args )
which effectively disables the getComments function.

20 comments:

  1. Hi William, You are Top Man :) just wanted say thank you. Code works perfectly.

    ReplyDelete
    Replies
    1. The big downside is that you have to re-do this after every jetpack update. But the load from those ajax calls just killed my site.

      Delete
  2. Hi, tried that and it turned off the comments link but the comments box was still there

    ReplyDelete
  3. Fixed it by taking out the form section section at line 102 but this is not a very elegant solution.

    ReplyDelete
  4. I think you'll like my solution. Give it a shot when you get time: http://aahank.com/2013/disable-comments-jetpack-carousel/

    Of course, it wouldn't be possible without the help of your solution. So, thank you for that. :)

    ReplyDelete
  5. Aahan, very nice. Both more thoroughly written and a more elegant solution. My concern was breaking carousel completely when another one of the WP Admins for my site updated jetpack. This way, worse case is that the update happens, we post a popular carousel, and the site slows to a crawl.

    In conjunction with this, I also wrote a short bash script that checks to make sure some of the edits I have put in place within Wordpress are still there and emails me daily if they are not.

    ReplyDelete
  6. May I please ask the opposite question? On some pages comments do not display - no text entry box - but I want them on all carousel pages. What is the difference that I can iron out? I see no obvious visual item in the dashboard.

    Thanks for allowing the question.

    ReplyDelete
  7. past this code in any loaded css file on your affected site:

    .jp-carousel-info {
    display: none;
    }

    evidence is on www.evopics.de

    ReplyDelete
  8. I had not used that particular bit before, but as I suspected it does not actually disable the ajax calls, it just disables the display of the data retrieved from the ajax call. I want to disable asking the server for comments, because these ajax calls are dynamic requests that require PHP and Database interaction causing load. We have had pages using Carousel which get a substantial number of requests for a relatively short period of times and these Ajax calls are sufficient to crush the server which performs handily after the above "return;" is added.

    ReplyDelete
  9. Hi William, for some reason my comments are still showing up. Have there been any changes to the code?

    Thank you : )

    ReplyDelete
    Replies
    1. We are continuing to use the same solution, re-implementing it each time after we update the jetpack plugin. We have the style bits in our themes style.css, and then the return mentioned above.

      Delete
  10. Are you using this in your css?

    .jp-carousel-info {
    display: none;
    }

    ReplyDelete
    Replies
    1. I have the following entries, not sure any of them do anything in our scenario:
      .jp-carousel-image-meta {
      display: none;
      }
      .jp-carousel-info {
      display: none;
      }
      #jp-carousel-comment-form {
      display:none;
      }

      Delete
  11. I simply want to tell you that I am new to weblog and definitely liked this blog site. Very likely I’m going to bookmark your blog . You absolutely have wonderful stories. Cheers for sharing with us your blog. John

    ReplyDelete
  12. This comment has been removed by a blog administrator.

    ReplyDelete
  13. Thank you! And this perhaps?
    ...plugins/jetpack/modules/carousel/jetpack-carousel.php

    Line 243 (or so) :

    $attr['data-comments-opened'] = $comments_opened; Change it to "closed"
    $attr['data-comments-opened'] = $comments_closed;
    Barbaric, but works... after closing ajax of course.

    Thank you!

    ReplyDelete
    Replies
    1. When the enemy is tearing down the walls, I have no issue resorting to barbary ;)

      Delete