fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-09-07 09:12 am

[dw-free] remove LJ::get_logtext2multi

[commit: http://hg.dwscoalition.org/dw-free/rev/39d8306976ad]

http://bugs.dwscoalition.org/show_bug.cgi?id=2911

Remove wrapper functions; convert code to use the newer versions directly.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/Entry.pm
  • htdocs/tools/recent_comments.bml
--------------------------------------------------------------------------------
diff -r ded9aadc4199 -r 39d8306976ad cgi-bin/LJ/Entry.pm
--- a/cgi-bin/LJ/Entry.pm	Tue Sep 07 16:47:28 2010 +0800
+++ b/cgi-bin/LJ/Entry.pm	Tue Sep 07 16:51:39 2010 +0800
@@ -1084,63 +1084,6 @@ use LJ::Poll;
 use LJ::Poll;
 use LJ::EmbedModule;
 use DW::External::Account;
-
-# <LJFUNC>
-# name: LJ::get_logtext2multi
-# des: Gets log text from clusters.
-# info: Fetches log text from clusters. Trying slaves first if available.
-# returns: hashref with keys being "jid jitemid", values being [ $subject, $body ]
-# args: idsbyc
-# des-idsbyc: A hashref where the key is the clusterid, and the data
-#             is an arrayref of [ ownerid, itemid ] array references.
-# </LJFUNC>
-sub get_logtext2multi {
-    return _get_posts_raw_wrapper(shift, "text");
-}
-
-# this function is used to translate the old get_logtext2multi function
-# into using the new get_posts_raw.  eventually, the above function should
-# be taken out of the rest of the code, at which point this function can also die.
-sub _get_posts_raw_wrapper {
-    # args:
-    #   { cid => [ [jid, jitemid]+ ] }
-    #   "text" or "props"
-    #   optional hashref to put return value in.  (see get_logtext2multi docs)
-    # returns: that hashref.
-    my ($idsbyc, $type, $ret) = @_;
-
-    my $opts = {};
-    if ($type eq 'text') {
-        $opts->{text_only} = 1;
-    } elsif ($type eq 'prop') {
-        $opts->{prop_only} = 1;
-    } else {
-        return undef;
-    }
-
-    my @postids;
-    while (my ($cid, $ids) = each %$idsbyc) {
-        foreach my $pair (@$ids) {
-            push @postids, [ $cid, $pair->[0], $pair->[1] ];
-        }
-    }
-    my $rawposts = LJ::get_posts_raw($opts, @postids);
-
-    # add replycounts fields to props
-    if ($type eq "prop") {
-        while (my ($k, $v) = each %{$rawposts->{"replycount"}||{}}) {
-            $rawposts->{prop}{$k}{replycount} = $rawposts->{replycount}{$k};
-        }
-    }
-
-    # translate colon-separated (new) to space-separated (old) keys.
-    $ret ||= {};
-    while (my ($id, $data) = each %{$rawposts->{$type}}) {
-        $id =~ s/:/ /;
-        $ret->{$id} = $data;
-    }
-    return $ret;
-}
 
 # <LJFUNC>
 # name: LJ::get_posts_raw
diff -r ded9aadc4199 -r 39d8306976ad htdocs/tools/recent_comments.bml
--- a/htdocs/tools/recent_comments.bml	Tue Sep 07 16:47:28 2010 +0800
+++ b/htdocs/tools/recent_comments.bml	Tue Sep 07 16:51:39 2010 +0800
@@ -143,16 +143,17 @@ body<=
 
     my $us = LJ::load_userids(keys %need_userid);
 
-    # setup the parameter to get_logtext2multi
-    my $need_logtext = {};
-    foreach my $need (values %need_logids) {
-        my $ju = $us->{$need->[0]};
-        next unless $ju;
-        push @{$need_logtext->{$ju->{clusterid}} ||= []}, $need;
+    # setup the parameter to get_posts_raw
+    my @need_logtext;
+    foreach my $need ( values %need_logids ) {
+        my ( $ownerid, $itemid ) = @$need;
+        my $ju = $us->{$ownerid} or next;
+        push @need_logtext, [ $ju->{clusterid}, $ownerid, $itemid ];
     }
 
     my $comment_text = LJ::get_talktext2( $u, keys %talkids );
-    my $log_text     = LJ::get_logtext2multi( $need_logtext );
+    my $log_data     = LJ::get_posts_raw( { text_only => 1 }, @need_logtext );
+    my $log_text     = $log_data->{text};
     my $root = $u->journal_base;
 
     # Begin "latest received" box. We only want to see this if we're a
@@ -231,7 +232,7 @@ body<=
             $ret .= "</td><td id='" . LJ::Talk::comment_htmlid( $talkid );
             $ret .= "' style='text-align: left; border-top: 1px solid #999; border-left: 1px solid #999'>";
 
-            my $subject = $log_text->{"$u->{userid} $r->{nodeid}"}[0];
+            my $subject = $log_text->{"$u->{userid}:$r->{nodeid}"}[0];
             LJ::CleanHTML::clean_subject(\$subject) if $subject ne "";
 
             $ret .= "<strong style='float: left; text-decoration: underline'>$subject</strong> " if $subject ne "";
@@ -309,7 +310,7 @@ body<=
 
             if (defined $lrow->{ditemid}) {
                 $hr_ago = "<a href='$talkurl'>$hr_ago</a>";
-                $subject = $log_text->{"$r->{journalid} $r->{nodeid}"}[0] || "$lrow->{ditemid}.html";
+                $subject = $log_text->{"$r->{journalid}:$r->{nodeid}"}[0] || "$lrow->{ditemid}.html";
                 LJ::CleanHTML::clean_subject(\$subject);
                 $subject = "$subject <a href='$logurl'>(link)</a>";
 
--------------------------------------------------------------------------------