Committer: afedorov
LJSUP-10900: Implement MessagePack protocol driver to access to Relation Service.U trunk/cgi-bin/LJ/RelationService/MysqlAPI.pm U trunk/cgi-bin/LJ/RelationService.pm U trunk/cgi-bin/LJ/User.pm
Modified: trunk/cgi-bin/LJ/RelationService/MysqlAPI.pm =================================================================== --- trunk/cgi-bin/LJ/RelationService/MysqlAPI.pm 2012-04-12 12:53:00 UTC (rev 21705) +++ trunk/cgi-bin/LJ/RelationService/MysqlAPI.pm 2012-04-12 13:04:40 UTC (rev 21706) @@ -794,4 +794,20 @@ return $mask+0; # force it to a numeric scalar } +sub delete_and_purge_completely { + my $class = shift; + my $u = shift; + my %opts = @_; + + return unless $u; + + my $dbh = LJ::get_db_writer(); + $dbh->do("DELETE FROM reluser WHERE userid=?", undef, $u->id); + $dbh->do("DELETE FROM friends WHERE userid=?", undef, $u->id); + $dbh->do("DELETE FROM friends WHERE friendid=?", undef, $u->id); + $dbh->do("DELETE FROM reluser WHERE targetid=?", undef, $u->id); + + return 1; +} + 1; Modified: trunk/cgi-bin/LJ/RelationService.pm =================================================================== --- trunk/cgi-bin/LJ/RelationService.pm 2012-04-12 12:53:00 UTC (rev 21705) +++ trunk/cgi-bin/LJ/RelationService.pm 2012-04-12 13:04:40 UTC (rev 21706) @@ -209,5 +209,24 @@ return $interface->get_groupmask($u, $friend, %opts); } +sub delete_and_purge_completely { + my $class = shift; + my $u = shift; + my %opts = @_; + + $u = LJ::want_user($u); + + return unless $u; + if ($class->_load_alt_api('write', 'F')) { + my $alt = $class->alt_api($u); + if ($alt) { + $alt->delete_and_purge_completely($u, %opts); + } + } + + my $interface = $class->relation_api($u); + return $interface->delete_and_purge_completely($u, %opts); +} + 1; Modified: trunk/cgi-bin/LJ/User.pm =================================================================== --- trunk/cgi-bin/LJ/User.pm 2012-04-12 12:53:00 UTC (rev 21705) +++ trunk/cgi-bin/LJ/User.pm 2012-04-12 13:04:40 UTC (rev 21706) @@ -3679,13 +3679,13 @@ # TODO: delete from global tables my $dbh = LJ::get_db_writer(); - my @tables = qw(user friends useridmap reluser priv_map infohistory email password); + my @tables = qw(user useridmap priv_map infohistory email password); foreach my $table (@tables) { $dbh->do("DELETE FROM $table WHERE userid=?", undef, $u->id); } + + LJ::RelationService->delete_and_purge_completely($u); - $dbh->do("DELETE FROM friends WHERE friendid=?", undef, $u->id); - $dbh->do("DELETE FROM reluser WHERE targetid=?", undef, $u->id); $dbh->do("DELETE FROM email_aliases WHERE alias=?", undef, $u->user . "\@$LJ::USER_DOMAIN"); $dbh->do("DELETE FROM community WHERE userid=?", undef, $u->id) @@ -4814,21 +4814,17 @@ my $u = shift; my $mode = shift; my $limit = shift; - - $limit = " LIMIT $limit" if $limit; - - my $sql = ''; + + my @uids; if ($mode eq 'friends'){ - $sql = "SELECT friendid FROM friends WHERE userid=? $limit"; + @uids = LJ::RelationService->find_relation_destinations($u, 'F', limit => $limit); } elsif ($mode eq 'friendofs'){ - $sql = "SELECT userid FROM friends WHERE friendid=? $limit"; + @uids = LJ::RelationService->find_relation_sources($u, 'F', limit => $limit); } else { Carp::croak("mode must either be 'friends' or 'friendofs'"); } - my $dbh = LJ::get_db_reader(); - my $uids = $dbh->selectcol_arrayref($sql, undef, $u->id); - return $uids; + return \@uids; } ## Returns exact friendsOf count. Whitout limit.