madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r22886: LJSUP-13445: Home page optimization: sta...

Committer: sbelyaev
LJSUP-13445: Home page optimization: stage 2
U   trunk/cgi-bin/LJ/Widget/RecentComments.pm
Modified: trunk/cgi-bin/LJ/Widget/RecentComments.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/RecentComments.pm	2012-09-13 12:08:50 UTC (rev 22885)
+++ trunk/cgi-bin/LJ/Widget/RecentComments.pm	2012-09-13 12:36:35 UTC (rev 22886)
@@ -4,7 +4,10 @@
 use base qw(LJ::Widget);
 use Carp qw(croak);
 use LJ::Text;
+use String::CRC32;
 
+use constant { WIDGET_EXPIRE_TIME => 60*60};
+
 sub need_res {
     return qw( stc/widgets/recentcomments.css );
 }
@@ -38,6 +41,16 @@
 
     my @comments = $u->get_recent_talkitems($limit, memcache => 1);
 
+    my $key_part = crc32(join(':', map { $_->{jtalkid} } @comments));
+    my $key = "recent_comments_widget:$key_part:" . 
+              ":" . $lncode .
+              ":" . $u->userid;
+
+    my $data = LJ::MemCache::get($key);
+    if ($data) {
+        return $data;
+    }
+
     my $ret;
 
     $ret .= "<div class='w-head'>";
@@ -95,6 +108,7 @@
     $ret .= "</ul>";
     $ret .= "</div>";
 
+    LJ::MemCache::set($key, $ret, WIDGET_EXPIRE_TIME);
     return $ret;
 }
 

Tags: livejournal, madeon, pm, sbelyaev
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments