madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r23071: LJSUP-13883: Journal pages optimizaiton ...

Committer: sbelyaev
LJSUP-13883: Journal pages optimizaiton : stage 1
U   trunk/cgi-bin/LJ/RelationService.pm
U   trunk/cgi-bin/LJ/S2.pm
Modified: trunk/cgi-bin/LJ/RelationService.pm
===================================================================
--- trunk/cgi-bin/LJ/RelationService.pm	2012-10-09 10:08:21 UTC (rev 23070)
+++ trunk/cgi-bin/LJ/RelationService.pm	2012-10-09 12:25:44 UTC (rev 23071)
@@ -9,6 +9,13 @@
 
 use Data::Dumper;
 
+my %singletons = ();
+
+sub reset_singletons {
+    %singletons = ();
+}
+
+
 sub _load_alt_api {
     my $class  = shift;
     my $method = shift;
@@ -136,7 +143,9 @@
     }
 
     my $interface = $class->relation_api($u);
-    return $interface->create_relation_to($u, $friend, $type, %opts);
+    my $result = $interface->create_relation_to($u, $friend, $type, %opts);
+    $singletons{$u->userid}->{$friend->userid}->{$type} = $result;
+    return $result;
 }
 
 
@@ -159,6 +168,7 @@
         }
     }
     my $interface = $class->relation_api($u);
+    delete $singletons{$u->userid}->{$friend->userid}->{$type};
     return $interface->remove_relation_to($u, $friend, $type);
 }
 
@@ -168,12 +178,15 @@
     my $friend = shift;
     my $type   = shift;
     my %opts   = @_;
-    
+
     $u = LJ::want_user($u);
     $friend = LJ::want_user($friend);
     
     return undef unless $u && $friend && $type;
 
+    return $singletons{$u->userid}->{$friend->userid}->{$type}
+        if exists $singletons{$u->userid}->{$friend->userid}->{$type};
+
     if ($class->_load_alt_api('read', $type)) {
         my $alt = $class->alt_api($u);
         if ($alt) {
@@ -182,7 +195,9 @@
     }
 
     my $interface = $class->relation_api($u);
-    return $interface->is_relation_to($u, $friend, $type, %opts);    
+    my $relation = $interface->is_relation_to($u, $friend, $type, %opts);   
+    $singletons{$u->userid}->{$friend->userid}->{$type} = $relation;
+    return $relation;
 }
 
 sub is_relation_type_to {

Modified: trunk/cgi-bin/LJ/S2.pm
===================================================================
--- trunk/cgi-bin/LJ/S2.pm	2012-10-09 10:08:21 UTC (rev 23070)
+++ trunk/cgi-bin/LJ/S2.pm	2012-10-09 12:25:44 UTC (rev 23071)
@@ -4018,8 +4018,13 @@
     my $remote = LJ::get_remote();
     my $null_link = { '_type' => 'Link', '_isnull' => 1 };
     my $real_user = $this->{'real_journalid'} ? LJ::want_user($this->{'real_journalid'}) : undef;
-    my $entry = LJ::Entry->new($journalu, ditemid => $this->{'itemid'});
 
+    my $entry = $this->{'_cache_entry_obj'}; 
+    if (!$entry) {
+        $entry = LJ::Entry->new($journalu, ditemid => $this->{'itemid'});
+        $this->{'_cache_entry_obj'} = $entry;
+    }
+
     my $link_override;
     LJ::run_hooks( 'override_s2_link', $journalu, $entry, $key,
         \$link_override );

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