[livejournal] r20511: LJSUP-10147: Implement abstract interace...
Committer: vad
LJSUP-10147: Implement abstract interace for access to friends relationsU trunk/cgi-bin/LJ/RelationService/MysqlAPI.pm U trunk/cgi-bin/LJ/User.pm
Modified: trunk/cgi-bin/LJ/RelationService/MysqlAPI.pm
===================================================================
--- trunk/cgi-bin/LJ/RelationService/MysqlAPI.pm 2011-11-09 07:39:27 UTC (rev 20510)
+++ trunk/cgi-bin/LJ/RelationService/MysqlAPI.pm 2011-11-09 07:45:56 UTC (rev 20511)
@@ -10,6 +10,10 @@
my $limit = $opts{limit} || 50000;
my $nogearman = $opts{nogearman} || 0;
+ ## stricly disable gearman,
+ ## load uids inporcess is faster than using gearman.
+ $nogearman = 1;
+
my $uids = $class->_friend_friendof_uids($u,
%opts,
limit => $limit,
@@ -26,6 +30,10 @@
my %opts = @_;
my $limit = $opts{limit} || 50000;
my $nogearman = $opts{nogearman} || 0;
+
+ ## stricly disable gearman
+ ## load uids inporcess is faster than using gearman.
+ $nogearman = 1;
my $uids = $class->_friend_friendof_uids($u,
%opts,
Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm 2011-11-09 07:39:27 UTC (rev 20510)
+++ trunk/cgi-bin/LJ/User.pm 2011-11-09 07:45:56 UTC (rev 20511)
@@ -4543,10 +4543,21 @@
sub friends_added_count {
my $u = shift;
- my %initial = ( map { $_ => 1 } @LJ::INITIAL_FRIENDS, @LJ::INITIAL_OPTIONAL_FRIENDS, $u->user );
-
- # return count of friends who were not initial
- return scalar grep { ! $initial{$_->user} } $u->friends;
+ my @friendids = $u->friend_uids;
+ if (@friendids>5_000) {
+ return scalar @friendids;
+ } else {
+ my %initial = ( map { $_ => 1 } @LJ::INITIAL_FRIENDS, @LJ::INITIAL_OPTIONAL_FRIENDS, $u->user );
+ my $count = 0;
+ my $users = LJ::load_userids(@friendids);
+ while(my ($uid, $u) = each %$users) {
+ next unless $u;
+ next if $initial{$u->user};
+ $count++;
+ }
+ # return count of friends who were not initial
+ return $count;
+ }
}
sub set_password {
