madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r20350: LJSUP-10119: reverting changes

Committer: sbelyaev
LJSUP-10119: reverting changes
U   trunk/cgi-bin/LJ/Entry.pm
U   trunk/cgi-bin/LJ/User.pm
Modified: trunk/cgi-bin/LJ/Entry.pm
===================================================================
--- trunk/cgi-bin/LJ/Entry.pm	2011-10-18 08:12:19 UTC (rev 20349)
+++ trunk/cgi-bin/LJ/Entry.pm	2011-10-18 08:33:17 UTC (rev 20350)
@@ -444,6 +444,7 @@
 sub prop {
     my ($self, $prop) = @_;
     $self->_load_props unless $self->{_loaded_props};
+
     return $self->{props} unless $prop;
     return $self->{props}{$prop};
 }
@@ -451,6 +452,7 @@
 sub props {
     my ($self, $prop) = @_;
     $self->_load_props unless $self->{_loaded_props};
+
     return $self->{props} || {};
 }
 
@@ -463,11 +465,13 @@
 
 sub _load_props {
     my $self = shift;
+
     return 1 if $self->{_loaded_props};
 
     my $props = {};
     LJ::load_log_props2($self->{u}, [ $self->jitemid ], $props);
     $self->handle_prefetched_props($props->{$self->jitemid});
+
     return 1;
 }
 
@@ -1460,7 +1464,7 @@
     my ($self) = @_;
 
     my $u = $self->{u};
-    return $self->jitemid == $u->get_sticky_entry();
+    return $self->jitemid == $u->get_sticky_entry_id();
 }
 
 sub can_delete_journal_item {
@@ -1690,7 +1694,6 @@
 
             while (my ($jid, $jitemid, $propid, $value) = $sth->fetchrow_array) {
                 my $id = "$jid:$jitemid";
-#                my $propname = $LJ::CACHE_PROPID{'log'}->{$propid}->{name};
                 $ret->{'prop'}->{$id}->{$propid} = $value;
                 $gotid{$id} = 1;
             }
@@ -2253,16 +2256,21 @@
 
     while ( my ($k, $v) = each %$mem ) {
         next unless $k =~ /(\w+):(\d+):(\d+)/;
+        my ( $memkey, $uid, $pid ) = ( $1, $2, $3 );
 
-        if ( $1 eq 'logprop2' ) {
+        if ( $memkey eq 'logprop2' ) {
             next unless ref $v eq "HASH";
-            delete $needprops{$3};
-            $hashref->{$3} = $v;
+
+            my @vkeys = keys %$v;
+            next if $vkeys[0] =~ /\D/;
+
+            delete $needprops{$pid};
+            $hashref->{$pid} = $v;
         }
 
-        if ( $1 eq 'rp' ) {
-            delete $needrc{$3};
-            $rc{$3} = int($v);  # change possible "0   " (true) to "0" (false)
+        if ( $memkey eq 'rp' ) {
+            delete $needrc{$pid};
+            $rc{$pid} = int($v);  # change possible "0   " (true) to "0" (false)
         }
     }
 
@@ -2281,6 +2289,7 @@
     unless ( $db ) {
         my $u = LJ::load_userid($userid);
         $db = @LJ::MEMCACHE_SERVERS ? LJ::get_cluster_def_reader($u) :  LJ::get_cluster_reader($u);
+
         return unless $db;
     }
 
@@ -2367,7 +2376,6 @@
 # des-jitemid: Journal itemid of item to delete.
 # des-quick: Optional boolean.  If set, only [dbtable[log2]] table
 #            is deleted from and the rest of the content is deleted
-#            later using [func[LJ::cmd_buffer_add]].
 # des-anum: The log item's anum, which'll be needed to delete lazily
 #           some data in tables which includes the anum, but the
 #           log row will already be gone so we'll need to store it for later.
@@ -2388,17 +2396,16 @@
     # delete tags
     LJ::Tags::delete_logtags($u, $jitemid);
 
-    #remove sticky
-    if ( $jitemid == $u->get_sticky_entry() ){
-        $u->remove_sticky_entry();
-    }
-
     LJ::run_hooks('report_entry_delete', $u->{'userid'}, $jitemid);
     my $dc = $u->log2_do(undef, "DELETE FROM log2 WHERE journalid=$jid AND jitemid=$jitemid $and");
     LJ::MemCache::delete([$jid, "log2:$jid:$jitemid"]);
     LJ::MemCache::decr([$jid, "log2ct:$jid"]) if $dc > 0;
     LJ::memcache_kill($jid, "dayct2");
 
+    if ( $jitemid == $u->get_sticky_entry_id() ){
+        $u->remove_sticky_entry_id();
+    }
+
     # if this is running the second time (started by the cmd buffer),
     # the log2 row will already be gone and we shouldn't check for it.
     my $sclient = $quick ? LJ::theschwartz() : undef;

Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm	2011-10-18 08:12:19 UTC (rev 20349)
+++ trunk/cgi-bin/LJ/User.pm	2011-10-18 08:33:17 UTC (rev 20350)
@@ -28,6 +28,7 @@
 use LJ::TimeUtil;
 use LJ::User::PropStorage;
 use LJ::FileStore;
+use LJ::RelationService;
 
 use Class::Autouse qw(
                       URI
@@ -3830,7 +3831,7 @@
         return 1 if $u->can_manage ($comm) or $comm->is_friend($u);
     }
 
-    return 1;
+    return 0;
 }
 
 sub can_upload_photo {
@@ -4564,7 +4565,7 @@
     my $limit = int(delete $args{limit}) || 50000;
     Carp::croak("unknown option") if %args;
 
-    return $u->_friend_friendof_uids(limit => $limit, mode => "friendofs");
+    return LJ::RelationService->find_relation_sources($u, limit => $limit);
 }
 
 # returns array of friend uids.  by default, limited at 50,000 items.
@@ -4573,10 +4574,9 @@
     my $limit = int(delete $args{limit}) || 50000;
     Carp::croak("unknown option") if %args;
 
-    return $u->_friend_friendof_uids(limit => $limit, mode => "friends");
+    return LJ::RelationService->find_relation_destinations($u, limit => $limit);
 }
 
-
 # helper method since the logic for both friends and friendofs is so similar
 sub _friend_friendof_uids {
     my $u = shift;
@@ -4615,6 +4615,7 @@
 # actually get friend/friendof uids, should not be called directly
 sub _friend_friendof_uids_do {
     my ($u, %args) = @_;
+## method is also called from load-friends-gm worker.
 
     my $limit = int(delete $args{limit}) || 50000;
     my $mode  = delete $args{mode};
@@ -6239,33 +6240,30 @@
 # return sticky entries existing
 sub has_sticky_entry {
     my ($self) = @_;
-    if ($self->prop("sticky_entry")) {
+    my $sticky_id  = $self->prop("sticky_entry_id");
+    if ($sticky_id) {
         return 1;
     }
     return 0;
 }
 
 # returns sticky entry jitemid
-sub get_sticky_entry {
+sub get_sticky_entry_id {
     my ($self) = @_;
-    return $self->prop("sticky_entry") || '';
+    return $self->prop("sticky_entry_id") || '';
 }
 
 # returns sticky entry jitemid
-sub remove_sticky {
+sub remove_sticky_id {
     my ($self) = @_;
-    my $ownerid = $self->userid;
-    $self->clear_prop("sticky_entry");
-    LJ::MemCache::delete([$ownerid, "log2lt:$ownerid"]);
+    $self->clear_prop("sticky_entry_id");
 }
 
 # set sticky entry? 
-sub set_sticky {
+sub set_sticky_id {
     my ($self, $itemid) = @_;
-    my $ownerid = $self->userid;
     die "itemid is not set" unless ($itemid);
-    $self->set_prop( sticky_entry => $itemid );
-    LJ::MemCache::delete([$ownerid, "log2lt:$ownerid"]);
+    $self->set_prop( sticky_entry_id => $itemid );
 }
 
 package LJ;
@@ -8659,163 +8657,16 @@
     return undef unless $userid;
     return undef if $LJ::FORCE_EMPTY_FRIENDS{$userid};
 
-    unless ($force) {
-        my $memc = _get_friends_memc($userid, $mask);
-        return $memc if $memc;
-    }
-    return {} if $memcache_only; # no friends
+    my $u = LJ::load_userid($userid);
 
-    # nothing from memcache, select all rows from the
-    # database and insert those into memcache
-    # then return rows that matched the given groupmask
-
-    # no gearman/gearman not wanted
-    my $gc = LJ::gearman_client();
-    return _get_friends_db($userid, $mask)
-        unless $gc && LJ::conf_test($LJ::LOADFRIENDS_USING_GEARMAN, $userid);
-
-    # invoke the gearman
-    my $friends;
-    my $arg = Storable::nfreeze({ userid => $userid, mask => $mask });
-    my $task = Gearman::Task->new("load_friends", \$arg,
-                                  {
-                                      uniq => "$userid",
-                                      on_complete => sub {
-                                          my $res = shift;
-                                          return unless $res;
-                                          $friends = Storable::thaw($$res);
-                                      }
-                                  });
-
-    my $ts = $gc->new_task_set();
-    $ts->add_task($task);
-    $ts->wait(timeout => 30); # 30 sec timeout
-
-    return $friends;
+    return LJ::RelationService->load_relation_destinations(
+            $u, uuid          => $uuid,
+                mask          => $mask,
+                memcache_only => $memcache_only,
+                force_db      => $force,
+                );
 }
 
-sub _get_friends_memc {
-    my $userid = shift
-        or Carp::croak("no userid to _get_friends_db");
-    my $mask = shift;
-
-    # memcache data version
-    my $ver = 1;
-
-    my $packfmt = "NH6H6NC";
-    my $packlen = 15;  # bytes
-
-    my @cols = qw(friendid fgcolor bgcolor groupmask showbydefault);
-
-    # first, check memcache
-    my $memkey = [$userid, "friends:$userid"];
-
-    my $memfriends = LJ::MemCache::get($memkey);
-    return undef unless $memfriends;
-
-    my %friends; # rows to be returned
-
-    # first byte of object is data version
-    # only version 1 is meaningful right now
-    my $memver = substr($memfriends, 0, 1, '');
-    return undef unless $memver == $ver;
-
-    # get each $packlen-byte row
-    while (length($memfriends) >= $packlen) {
-        my @row = unpack($packfmt, substr($memfriends, 0, $packlen, ''));
-
-        # don't add into %friends hash if groupmask doesn't match
-        next if $mask && ! ($row[3]+0 & $mask+0);
-
-        # add "#" to beginning of colors
-        $row[$_] = "\#$row[$_]" foreach 1..2;
-
-        # turn unpacked row into hashref
-        my $fid = $row[0];
-        my $idx = 1;
-        foreach my $col (@cols[1..$#cols]) {
-            $friends{$fid}->{$col} = $row[$idx];
-            $idx++;
-        }
-    }
-
-    # got from memcache, return
-    return \%friends;
-}
-
-sub _get_friends_db {
-    my $userid = shift
-        or Carp::croak("no userid to _get_friends_db");
-    my $mask = shift;
-
-    my $dbh = LJ::get_db_writer();
-
-    my $lockname = "get_friends:$userid";
-    my $release_lock = sub {
-        LJ::release_lock($dbh, "global", $lockname);
-    };
-
-    # get a lock
-    my $lock = LJ::get_lock($dbh, "global", $lockname);
-    return {} unless $lock;
-
-    # in lock, try memcache
-    my $memc = _get_friends_memc($userid, $mask);
-    if ($memc) {
-        $release_lock->();
-        return $memc;
-    }
-
-    # inside lock, but still not populated, query db
-
-    # memcache data info
-    my $ver = 1;
-    my $memkey = [$userid, "friends:$userid"];
-    my $packfmt = "NH6H6NC";
-    my $packlen = 15;  # bytes
-
-    # columns we're selecting
-    my @cols = qw(friendid fgcolor bgcolor groupmask showbydefault);
-
-    my $mempack = $ver; # full packed string to insert into memcache, byte 1 is dversion
-    my %friends;        # friends object to be returned, all groupmasks match
-
-    my $sth = $dbh->prepare("SELECT friendid, fgcolor, bgcolor, groupmask, showbydefault " .
-                            "FROM friends WHERE userid=?");
-    $sth->execute($userid);
-    die $dbh->errstr if $dbh->err;
-    while (my @row = $sth->fetchrow_array) {
-
-        # convert color columns to hex
-        $row[$_] = sprintf("%06x", $row[$_]) foreach 1..2;
-
-        my $newpack = pack($packfmt, @row);
-        last if length($mempack) + length($newpack) > 950*1024;
-
-        $mempack .= $newpack;
-
-        # unless groupmask matches, skip adding to %friends
-        next if $mask && ! ($row[3]+0 & $mask+0);
-
-        # add "#" to beginning of colors
-        $row[$_] = "\#$row[$_]" foreach 1..2;
-
-        my $fid = $row[0];
-        my $idx = 1;
-        foreach my $col (@cols[1..$#cols]) {
-            $friends{$fid}->{$col} = $row[$idx];
-            $idx++;
-        }
-    }
-
-    LJ::MemCache::add($memkey, $mempack);
-
-    # finished with lock, release it
-    $release_lock->();
-
-    return \%friends;
-}
-
 # <LJFUNC>
 # name: LJ::get_friendofs
 # des: Returns userids of friendofs for a given user.
@@ -8829,27 +8680,11 @@
     my $userid = LJ::want_userid($uuid);
     return undef unless $userid;
 
-    # first, check memcache
-    my $memkey = [$userid, "friendofs:$userid"];
-
-    unless ($opts->{force}) {
-        my $memfriendofs = LJ::MemCache::get($memkey);
-        return @$memfriendofs if $memfriendofs;
-    }
-
-    # nothing from memcache, select all rows from the
-    # database and insert those into memcache
-
-    my $dbh = LJ::get_db_writer();
-    my $limit = $opts->{force} ? '' : " LIMIT " . ($LJ::MAX_FRIENDOF_LOAD+1);
-    my $friendofs = $dbh->selectcol_arrayref
-        ("SELECT userid FROM friends WHERE friendid=?$limit",
-         undef, $userid) || [];
-    die $dbh->errstr if $dbh->err;
-
-    LJ::MemCache::add($memkey, $friendofs);
-
-    return @$friendofs;
+    my $u = LJ::load_userid($userid);
+    return LJ::RelationService->find_relation_sources($u, 
+            nolimit        => $opts->{force} || 0,
+            skip_memcached => $opts->{force},
+            );
 }
 
 # <LJFUNC>

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