holyandrew (holyandrew) wrote in changelog,
holyandrew
holyandrew
changelog

[livejournal] r22859: LJSUP-13263: Wrong counter of friends

Committer: akanashin
LJSUP-13263: Wrong counter of friends
U   trunk/cgi-bin/LJ/Console/Command/BanSet.pm
U   trunk/cgi-bin/LJ/Console/Command/BanUnset.pm
U   trunk/cgi-bin/LJ/User.pm
Modified: trunk/cgi-bin/LJ/Console/Command/BanSet.pm
===================================================================
--- trunk/cgi-bin/LJ/Console/Command/BanSet.pm	2012-09-11 11:12:56 UTC (rev 22858)
+++ trunk/cgi-bin/LJ/Console/Command/BanSet.pm	2012-09-11 12:15:03 UTC (rev 22859)
@@ -52,13 +52,8 @@
     return $self->error("You have reached the maximum number of bans.  Unban someone and try again.")
         if scalar(@$banlist) >= ($LJ::MAX_BANS || 5000);
 
-    LJ::set_rel($journal, $banuser, 'B');
+    $journal->ban_user($banuser);
 
-    LJ::User::UserlogRecord::BanSet->create( $journal,
-        'bannedid' => $banuser->userid, 'remote' => $remote );
-
-    LJ::run_hooks('ban_set', $journal, $banuser);
-
     return $self->print("User " . $banuser->user . " banned from " . $journal->user);
 }
 

Modified: trunk/cgi-bin/LJ/Console/Command/BanUnset.pm
===================================================================
--- trunk/cgi-bin/LJ/Console/Command/BanUnset.pm	2012-09-11 11:12:56 UTC (rev 22858)
+++ trunk/cgi-bin/LJ/Console/Command/BanUnset.pm	2012-09-11 12:15:03 UTC (rev 22859)
@@ -58,13 +58,11 @@
         while (my @ids_batch = splice(@$banids, 0 => 500)){
             ## load users
             my $us = LJ::load_userids(@ids_batch);
-            while (my (undef, $banuser) = each %$us){
-                ## We are interested in suspended or expunged users only.
-                if ($banuser->is_suspended or $banuser->is_expunged){
-                    ## remove suspended user from ban list
-                    ban_unset($remote, $journal, $banuser);
-                    $self->print("User " . $banuser->user . " unbanned from " . $journal->user);
-                }
+            ## unban users multi
+            @ids_batch = grep { $us->{$_}->is_suspended || $us->{$_}->is_expunged } @ids_batch;
+            $journal->unban_user_multi(@ids_batch);
+            for (@ids_batch) {
+                $self->print("User " . $us->{$_}->user . " unbanned from " . $journal->user);
             }
         }
     } else {
@@ -73,7 +71,7 @@
         return $self->error("Unknown account: $user")
             unless $banuser;
 
-        ban_unset($remote, $journal, $banuser);
+        $journal->unban_user_multi($banuser->userid);
 
         return $self->print("User " . $banuser->user . " unbanned from " . $journal->user);
     }
@@ -81,21 +79,4 @@
     return 1;
 }
 
-sub ban_unset {
-    my ($remote, $journal, $banuser) = @_;
-
-    LJ::clear_rel($journal, $banuser, 'B');
-
-    LJ::User::UserlogRecord::BanUnset->create( $journal,
-        'bannedid' => $banuser->userid, 'remote' => $remote );
-
-    LJ::run_hooks('ban_unset', $journal, $banuser);
-
-
-}
-
-
-
-
-
 1;

Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm	2012-09-11 11:12:56 UTC (rev 22858)
+++ trunk/cgi-bin/LJ/User.pm	2012-09-11 12:15:03 UTC (rev 22859)
@@ -5303,7 +5303,12 @@
     LJ::run_hooks('ban_set', $u, $ban_u);
 
     my @friendof_uids  = $u->friendof_uids;
-    if (grep {$ban_u->userid} @friendof_uids) {
+    my %friendof_uids_hash = map {$_ => 1} @friendof_uids;
+
+    my $ban_uids = LJ::load_rel_user($u, 'B');
+    my %ban_user_hash = map {$_ => 1} @$ban_uids;
+
+    if ($friendof_uids_hash{$ban_u->id} && !$ban_user_hash{$ban_u->id}) {
          LJ::MemCache::decr($u->user.'_count_friendof') if $ban_u->{journaltype} eq 'P' || $ban_u->{journaltype} eq 'I';
          LJ::MemCache::decr($u->user.'_count_member')   if $ban_u->{journaltype} eq 'C' || $ban_u->{journaltype} eq 'S';
     }
@@ -5314,52 +5319,58 @@
 sub ban_user_multi {
     my ($u, @banlist) = @_;
 
-    LJ::set_rel_multi(map { [$u->id, $_, 'B'] } @banlist);
-
     my $us = LJ::load_userids(@banlist);
     my $remote = LJ::get_remote();
 
     my @friendof_uids  = $u->friendof_uids;
     my %friendof_uids_hash = map {$_ => 1} @friendof_uids;
 
+    my $ban_uids = LJ::load_rel_user($u, 'B');
+    my %ban_user_hash = map {$_ => 1} @$ban_uids;
+
     foreach my $banuid (@banlist) {
         LJ::User::UserlogRecord::BanSet->create( $u,
             'bannedid' => $banuid, 'remote' => $remote );
 
         LJ::run_hooks('ban_set', $u, $us->{$banuid}) if $us->{$banuid};
 
-        if ($friendof_uids_hash{$banuid}) {
+        if ($friendof_uids_hash{$banuid} && !$ban_user_hash{$banuid}) {
             LJ::MemCache::decr($u->user.'_count_friendof') if $us->{$banuid}->{journaltype} eq 'P' || $us->{$banuid}->{journaltype} eq 'I';
             LJ::MemCache::decr($u->user.'_count_member')   if $us->{$banuid}->{journaltype} eq 'C' || $us->{$banuid}->{journaltype} eq 'S';
         }
     }
 
+    LJ::set_rel_multi(map { [$u->id, $_, 'B'] } @banlist);
+
     return 1;
 }
 
 sub unban_user_multi {
     my ($u, @unbanlist) = @_;
 
-    LJ::clear_rel_multi(map { [$u->id, $_, 'B'] } @unbanlist);
-
     my $us = LJ::load_userids(@unbanlist);
     my $remote = LJ::get_remote();
 
     my @friendof_uids  = $u->friendof_uids;
     my %friendof_uids_hash = map {$_ => 1} @friendof_uids;
 
+    my $ban_uids = LJ::load_rel_user($u, 'B');
+    my %ban_user_hash = map {$_ => 1} @$ban_uids;
+
     foreach my $banuid (@unbanlist) {
         LJ::User::UserlogRecord::BanUnset->create( $u,
             'bannedid' => $banuid, 'remote' => $remote );
 
         LJ::run_hooks('ban_unset', $u, $us->{$banuid}) if $us->{$banuid};
 
-        if ($friendof_uids_hash{$banuid}) {
+        if ($friendof_uids_hash{$banuid} && $ban_user_hash{$banuid}) {
             LJ::MemCache::incr($u->user.'_count_friendof') if $us->{$banuid}->{journaltype} eq 'P' || $us->{$banuid}->{journaltype} eq 'I';
             LJ::MemCache::incr($u->user.'_count_member')   if $us->{$banuid}->{journaltype} eq 'C' || $us->{$banuid}->{journaltype} eq 'S';
         }
     }
 
+    LJ::clear_rel_multi(map { [$u->id, $_, 'B'] } @unbanlist);
+
     return 1;
 }
 

Tags: akanashin, holyandrew, livejournal, pm
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