mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2012-02-10 03:54 am

[dw-free] Optimize comment filtering

[commit: http://hg.dwscoalition.org/dw-free/rev/064d26890498]

Optimize comment filtering

This little chunk of code was responsible for ~4 seconds of load time on an
entry with 5,000 comments. With this little change (which admittedly is kind
of ugly) that drops a lot -- almost instant.

Patch by [staff profile] mark.

Files modified:
  • cgi-bin/LJ/Talk.pm
--------------------------------------------------------------------------------
diff -r 43f4ee4c3b3e -r 064d26890498 cgi-bin/LJ/Talk.pm
--- a/cgi-bin/LJ/Talk.pm	Thu Feb 09 23:10:32 2012 +0000
+++ b/cgi-bin/LJ/Talk.pm	Fri Feb 10 03:54:52 2012 +0000
@@ -739,8 +739,10 @@
 
         # find all singletons that LJ::Comment knows about, then grep for the ones we've set in
         # this get_talk_data call (ones for this userid / nodeid)
+        my $uid = $u->userid;
+        LJ::Comment->preload_rows();
         my @comments_for_entry =
-            grep { $_->journalid == $u->userid && $_->nodeid == $nodeid } LJ::Comment->all_singletons;
+            grep { $_->{journalid} == $uid && $_->{nodeid} == $nodeid } LJ::Comment->all_singletons;
 
         $entry->set_comment_list(@comments_for_entry);
     };
--------------------------------------------------------------------------------