Типа я (zilogic) wrote in changelog,
Типа я
zilogic
changelog

[livejournal] r20192: LJSUP-9804: Problem with writing propert...

Committer: amyshkin
LJSUP-9804: Problem with writing properties data for entries on Omega/Alpha/Beta servers
U   trunk/cgi-bin/LJ/DelayedEntry.pm
U   trunk/cgi-bin/LJ/Entry.pm
U   trunk/cgi-bin/LJ/Talk/Post.pm
U   trunk/cgi-bin/ljprotocol.pl
Modified: trunk/cgi-bin/LJ/DelayedEntry.pm
===================================================================
--- trunk/cgi-bin/LJ/DelayedEntry.pm	2011-09-30 09:48:43 UTC (rev 20191)
+++ trunk/cgi-bin/LJ/DelayedEntry.pm	2011-10-03 05:03:31 UTC (rev 20192)
@@ -1357,10 +1357,10 @@
 
         my %logprops;
         LJ::set_logprop($journal, $jitemid, $propset, \%logprops) if %$propset;
-        
+
         # if set_logprop modified props above, we can set the memcache key
         # to be the hashref of modified props, since this is a new post
-        LJ::MemCache::set([$journal->{'userid'}, "logprop:$journal->{'userid'}:$jitemid"],
+        LJ::MemCache::set([$journal->{'userid'}, "logprop2:$journal->{'userid'}:$jitemid"],
         \%logprops) if %logprops;
     }
 

Modified: trunk/cgi-bin/LJ/Entry.pm
===================================================================
--- trunk/cgi-bin/LJ/Entry.pm	2011-09-30 09:48:43 UTC (rev 20191)
+++ trunk/cgi-bin/LJ/Entry.pm	2011-10-03 05:03:31 UTC (rev 20192)
@@ -467,7 +467,8 @@
 
     my $props = {};
     LJ::load_log_props2($self->{u}, [ $self->jitemid ], $props);
-
+use Data::Dumper;
+warn Dumper($props);
     $self->handle_prefetched_props($props->{$self->jitemid});
     return 1;
 }
@@ -1549,8 +1550,7 @@
 #            - prop_only:  Retrieve only props, no text (used to support old API).
 # des-id: An arrayref of [ clusterid, ownerid, itemid ].
 # </LJFUNC>
-sub get_posts_raw
-{
+sub get_posts_raw {
     my $opts = ref $_[0] eq "HASH" ? shift : {};
     my $ret = {};
     my $sth;
@@ -1582,24 +1582,30 @@
     # but that means we need to grep out each cluster's jids when
     # we do per-cluster queries on the databases.
     my %cidsbyjid;
+
     foreach my $post (@_) {
         my ($cid, $jid, $jitemid) = @{$post};
         my $id = "$jid:$jitemid";
-        if (not defined $single_user) {
+
+        if ( not defined $single_user ) {
             $single_user = $jid;
-        } elsif ($single_user and $jid != $single_user) {
+        }
+        elsif ( $single_user and $jid != $single_user ) {
             # multiple users
             $single_user = 0;
         }
+
         $cids{$cid} = 1;
         $cidsbyjid{$jid} = $cid;
+
         unless ($opts->{prop_only}) {
             $needtext->{$cid}{$id} = 1;
             push @mem_keys, [$jid,"logtext:$cid:$id"];
         }
+
         unless ($opts->{text_only}) {
             $needprop->{$cid}{$id} = 1;
-            push @mem_keys, [$jid,"logprop:$id"];
+            push @mem_keys, [$jid,"logprop2:$id"];
             $needrc->{$cid}{$id} = 1;
             push @mem_keys, [$jid,"rp:$id"];
         }
@@ -1607,29 +1613,38 @@
 
     # first, check memcache.
     my $mem = LJ::MemCache::get_multi(@mem_keys) || {};
+
     while (my ($k, $v) = each %$mem) {
         next unless defined $v;
         next unless $k =~ /(\w+):(?:\d+:)?(\d+):(\d+)/;
+
         my ($type, $jid, $jitemid) = ($1, $2, $3);
         my $cid = $cidsbyjid{$jid};
         my $id = "$jid:$jitemid";
+
         if ($type eq "logtext") {
-            delete $needtext->{$cid}{$id};
-            $ret->{text}{$id} = $v;
-        } elsif ($type eq "logprop" && ref $v eq "HASH") {
-            delete $needprop->{$cid}{$id};
-            $ret->{prop}{$id} = $v;
-        } elsif ($type eq "rp") {
-            delete $needrc->{$cid}{$id};
-            $ret->{replycount}{$id} = int($v); # remove possible spaces
+            delete $needtext->{$cid}->{$id};
+            $ret->{'text'}->{$id} = $v;
         }
+        elsif ($type eq "logprop2" && ref $v eq "HASH") {
+            delete $needprop->{$cid}->{$id};
+            $ret->{'prop'}->{$id} = $v;
+        }
+        elsif ($type eq "rp") {
+            delete $needrc->{$cid}->{$id};
+            $ret->{'replycount'}->{$id} = int($v); # remove possible spaces
+        }
     }
 
     # we may be done already.
     return $ret if $opts->{memcache_only};
-    return $ret unless values %$needtext or values %$needprop
-        or values %$needrc;
 
+    unless ( values %$needtext or values %$needprop
+        or values %$needrc ) {
+        convert_href_props( $ret->{'prop'} );
+        return $ret;
+    }
+
     # otherwise, hit the database.
     foreach my $cid (keys %cids) {
         # for each cluster, get the text/props we need from it.
@@ -1674,15 +1689,17 @@
                                 "FROM logprop2 WHERE $in");
             $sth->execute;
             my %gotid;
+
             while (my ($jid, $jitemid, $propid, $value) = $sth->fetchrow_array) {
                 my $id = "$jid:$jitemid";
-                my $propname = $LJ::CACHE_PROPID{'log'}->{$propid}{name};
-                $ret->{prop}{$id}{$propname} = $value;
+#                my $propname = $LJ::CACHE_PROPID{'log'}->{$propid}->{name};
+                $ret->{prop}->{$id}->{$propid} = $value;
                 $gotid{$id} = 1;
             }
+
             foreach my $id (keys %gotid) {
                 my ($jid, $jitemid) = map { $_ + 0 } split(/:/, $id);
-                LJ::MemCache::add([$jid, "logprop:$id"], $ret->{prop}{$id});
+                LJ::MemCache::add([$jid, "logprop2:$id"], $ret->{prop}->{$id});
                 delete $cneedprop->{$id};
             }
         };
@@ -1690,9 +1707,11 @@
         my $fetchrc = sub {
             my $db = shift;
             return unless %$cneedrc;
+
             my $in = $make_in->(keys %$cneedrc);
             $sth = $db->prepare("SELECT journalid, jitemid, replycount FROM log2 WHERE $in");
             $sth->execute;
+
             while (my ($jid, $jitemid, $rc) = $sth->fetchrow_array) {
                 my $id = "$jid:$jitemid";
                 $ret->{replycount}{$id} = $rc;
@@ -1708,18 +1727,22 @@
 
         # run the fetch functions on the proper databases, with fallbacks if necessary.
         my ($dbcm, $dbcr);
+
         if (@LJ::MEMCACHE_SERVERS or $opts->{use_master}) {
             $dbcm ||= LJ::get_cluster_master($cid) or $dberr->();
             $fetchtext->($dbcm) if %$cneedtext;
             $fetchprop->($dbcm) if %$cneedprop;
             $fetchrc->($dbcm) if %$cneedrc;
-        } else {
+        }
+        else {
             $dbcr ||= LJ::get_cluster_reader($cid);
+
             if ($dbcr) {
                 $fetchtext->($dbcr) if %$cneedtext;
                 $fetchprop->($dbcr) if %$cneedprop;
                 $fetchrc->($dbcr) if %$cneedrc;
             }
+
             # if we still need some data, switch to the master.
             if (%$cneedtext or %$cneedprop) {
                 $dbcm ||= LJ::get_cluster_master($cid) or $dberr->();
@@ -1734,9 +1757,11 @@
         # for all posts that didn't have any props.
         foreach my $id (keys %$cneedprop) {
             my ($jid, $jitemid) = map { $_ + 0 } split(/:/, $id);
-            LJ::MemCache::set([$jid, "logprop:$id"], {});
+            LJ::MemCache::set([$jid, "logprop2:$id"], {});
         }
     }
+
+    convert_href_props( $ret->{'prop'} );
     return $ret;
 }
 
@@ -2161,8 +2186,7 @@
 sub get_itemid_after2  { return get_itemid_near2(@_, "after");  }
 sub get_itemid_before2 { return get_itemid_near2(@_, "before"); }
 
-sub set_logprop
-{
+sub set_logprop {
     my ($u, $jitemid, $hashref, $logprops) = @_;  # hashref to set, hashref of what was done
 
     $jitemid += 0;
@@ -2170,15 +2194,19 @@
     my $kill_mem = 0;
     my $del_ids;
     my $ins_values;
+
     while (my ($k, $v) = each %{$hashref||{}}) {
         my $prop = LJ::get_prop("log", $k);
         next unless $prop;
+
         $kill_mem = 1 unless $prop eq "commentalter";
+
         if ($v) {
             $ins_values .= "," if $ins_values;
             $ins_values .= "($uid, $jitemid, $prop->{'id'}, " . $u->quote($v) . ")";
             $logprops->{$k} = $v;
-        } else {
+        }
+        else {
             $del_ids .= "," if $del_ids;
             $del_ids .= $prop->{'id'};
         }
@@ -2189,7 +2217,7 @@
     $u->do("DELETE FROM logprop2 WHERE journalid=? AND jitemid=? ".
            "AND propid IN ($del_ids)", undef, $u->{'userid'}, $jitemid) if $del_ids;
 
-    LJ::MemCache::delete([$uid,"logprop:$uid:$jitemid"]) if $kill_mem;
+    LJ::MemCache::delete([$uid,"logprop2:$uid:$jitemid"]) if $kill_mem;
 }
 
 # <LJFUNC>
@@ -2217,7 +2245,7 @@
         my $id          = $_ + 0;
         $needprops{$id} = 1;
         $needrc{$id}    = 1;
-        push @memkeys, [$userid, "logprop:$userid:$id"];
+        push @memkeys, [$userid, "logprop2:$userid:$id"];
         push @memkeys, LJ::Entry::reply_count_memkey($userid, $id);
     }
 
@@ -2228,7 +2256,7 @@
     while ( my ($k, $v) = each %$mem ) {
         next unless $k =~ /(\w+):(\d+):(\d+)/;
 
-        if ( $1 eq 'logprop' ) {
+        if ( $1 eq 'logprop2' ) {
             next unless ref $v eq "HASH";
             delete $needprops{$3};
             $hashref->{$3} = $v;
@@ -2244,8 +2272,14 @@
         $hashref->{$_}{'replycount'} = $rc{$_};
     }
 
-    return unless %needprops || %needrc;
+    unless ( %needprops || %needrc ) {
+        for my $jitemid ( keys %$hashref ) {
+            convert_href_props( $hashref->{$jitemid} );
+        }
 
+        return;
+    }
+
     unless ( $db ) {
         my $u = LJ::load_userid($userid);
         $db = @LJ::MEMCACHE_SERVERS ? LJ::get_cluster_def_reader($u) :  LJ::get_cluster_reader($u);
@@ -2260,11 +2294,11 @@
         $sth->execute($userid);
 
         while (my ($jitemid, $propid, $value) = $sth->fetchrow_array) {
-            $hashref->{$jitemid}->{$LJ::CACHE_PROPID{'log'}->{$propid}->{'name'}} = $value;
+            $hashref->{$jitemid}->{ $propid } = $value;
         }
 
         foreach my $id (keys %needprops) {
-            LJ::MemCache::set([$userid,"logprop:$userid:$id"], $hashref->{$id} || {});
+            LJ::MemCache::set([$userid,"logprop2:$userid:$id"], $hashref->{$id} || {});
           }
     }
 
@@ -2278,7 +2312,31 @@
         }
     }
 
+    for my $jitemid ( keys %$hashref ) {
+        convert_href_props( $hashref->{$jitemid} );
+    }
+}
 
+# <LJFUNC>
+# name: LJ::convert_href_props
+# class:
+# des:
+# info:
+# args:
+# des-:
+# returns:
+# </LJFUNC>
+sub convert_href_props {
+    my $href = shift;
+    my %new_href;
+
+    for my $key ( keys %$href ) {
+        my $prop = delete $href->{$key};
+        next unless exists $LJ::CACHE_PROPID{'log'}->{$key};
+        $new_href{ $LJ::CACHE_PROPID{'log'}->{$key}->{'name'} } = $prop;
+    }
+
+    %$href = %new_href;
 }
 
 # <LJFUNC>

Modified: trunk/cgi-bin/LJ/Talk/Post.pm
===================================================================
--- trunk/cgi-bin/LJ/Talk/Post.pm	2011-09-30 09:48:43 UTC (rev 20191)
+++ trunk/cgi-bin/LJ/Talk/Post.pm	2011-10-03 05:03:31 UTC (rev 20192)
@@ -230,7 +230,7 @@
 sub init {
     my ($form, $remote, $need_captcha, $errret) = @_;
     my $sth = undef;
-    
+
     my $err = sub {
         my $error = shift;
         push @$errret, $error;

Modified: trunk/cgi-bin/ljprotocol.pl
===================================================================
--- trunk/cgi-bin/ljprotocol.pl	2011-09-30 09:48:43 UTC (rev 20191)
+++ trunk/cgi-bin/ljprotocol.pl	2011-10-03 05:03:31 UTC (rev 20192)
@@ -2137,7 +2137,7 @@
         ## Scan post for spam
         LJ::run_hook('spam_community_detector', $uowner, $req, \$need_moderated);
     }
-    
+
     if ( $req->{ver} > 1 ) {
         my $use_delayed = $req->{'custom_time'} ||
                     !(exists $flags->{'use_custom_time'});
@@ -2455,7 +2455,7 @@
 
         # if set_logprop modified props above, we can set the memcache key
         # to be the hashref of modified props, since this is a new post
-        LJ::MemCache::set([$uowner->{'userid'}, "logprop:$uowner->{'userid'}:$jitemid"],
+        LJ::MemCache::set([$uowner->{'userid'}, "logprop2:$uowner->{'userid'}:$jitemid"],
                           \%logprops) if %logprops;
     }
 

Tags: livejournal, pl, pm, zilogic
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