[livejournal] r21470: LJSUP-11581: Change LJ::load_user_props(...
Committer: anazarov
LJSUP-11581: Change LJ::load_user_props() implementation to use LJ::load_user_props_multi()U trunk/cgi-bin/LJ/Talk.pm U trunk/cgi-bin/LJ/User.pm
Modified: trunk/cgi-bin/LJ/Talk.pm
===================================================================
--- trunk/cgi-bin/LJ/Talk.pm 2012-03-20 11:24:21 UTC (rev 21469)
+++ trunk/cgi-bin/LJ/Talk.pm 2012-03-20 13:08:24 UTC (rev 21470)
@@ -1682,7 +1682,7 @@
my %up = ();
if (%users_to_load) {
LJ::load_userids_multiple([ map { $_, \$up{$_} } keys %users_to_load ]);
- LJ::load_user_props_multi(undef, [values %up], [qw{ custom_usericon }]);
+ LJ::load_user_props_multi([values %up], [qw{ custom_usericon }]);
# fill in the 'userpost' member on each post being shown
while (my ($id, $post) = each %$posts) {
Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm 2012-03-20 11:24:21 UTC (rev 21469)
+++ trunk/cgi-bin/LJ/User.pm 2012-03-20 13:08:24 UTC (rev 21470)
@@ -6622,6 +6622,7 @@
# args: dbarg?, u, opts?, propname*
# des-opts: hashref of opts. set key 'cache' to use memcache.
# des-propname: the name of a property from the [dbtable[userproplist]] table.
+# README: this function is overridden below if user_props_multi flag is enabled
# </LJFUNC>
sub load_user_props {
&nodb;
@@ -6735,8 +6736,33 @@
}
}
+sub load_user_props_v2 {
+ my ($u, @props) = @_;
+ return unless ref $u;
+
+ my $opts = ref $props[0]? shift @props : {};
+ unless ( delete $opts->{'reload'} ) {
+ @props = grep { not exists $u->{$_} } @props;
+ }
+
+ LJ::load_user_props_multi([$u], \@props, $opts);
+
+ LJ::User->init_userprop_def;
+
+ foreach my $propname (@props) {
+ next if defined $u->{$propname};
+ next unless defined $LJ::USERPROP_DEF{$propname};
+ $u->{$propname} = $LJ::USERPROP_DEF{$propname};
+ }
+}
+
+if ( LJ::is_enabled('user_props_multi') ) {
+ no strict 'refs';
+ *load_user_props = \&LJ::load_user_props_v2;
+}
+
sub load_user_props_multi {
- my ($class, $users, $props, $opts) = @_;
+ my ($users, $props, $opts) = @_;
my $use_master = $opts->{'use_master'};
$props = [grep { defined and not ref } @$props];
