fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-06-10 10:46 am

[dw-free] migrate LJ::load_user_props -> $u->preload_props

[commit: http://hg.dwscoalition.org/dw-free/rev/e70d0cbd7897]

http://bugs.dwscoalition.org/show_bug.cgi?id=2653

Code cleanup - instead of preloading the property then looking it up in the
hash, just call ->prop which does that for us. Cleaner, less chance of
forgetting something. Cleanup of probably old code.

Patch by [personal profile] kareila.

Files modified:
  • bin/maint/generic.pl
  • bin/renameuser.pl
  • cgi-bin/Apache/LiveJournal.pm
  • cgi-bin/Apache/LiveJournal/Interface/AtomAPI.pm
  • cgi-bin/Apache/LiveJournal/Interface/Blogger.pm
  • cgi-bin/LJ/Blob.pm
  • cgi-bin/LJ/S2.pm
  • cgi-bin/LJ/Tags.pm
  • cgi-bin/LJ/Talk.pm
  • cgi-bin/ljemailgateway-web.pl
  • cgi-bin/ljemailgateway.pl
  • cgi-bin/ljprotocol.pl
  • cgi-bin/weblib.pl
  • htdocs/allpics.bml
  • htdocs/community/sentinvites.bml
  • htdocs/feeds/index.bml
  • htdocs/manage/pubkey.bml
  • htdocs/talkread.bml
  • htdocs/tools/memories.bml
--------------------------------------------------------------------------------
diff -r 1543dbb2b1b3 -r e70d0cbd7897 bin/maint/generic.pl
--- a/bin/maint/generic.pl	Thu Jun 10 18:44:08 2010 +0800
+++ b/bin/maint/generic.pl	Thu Jun 10 18:52:09 2010 +0800
@@ -53,8 +53,7 @@
             print "$mid ";
             next unless $mus->{$mid};
             next if $email{$mus->{$mid}{email}}++;
-            $mus->{$mid}->preload_props( 'opt_communityjoinemail' );
-            next unless $mus->{$mid}{opt_communityjoinemail} eq 'D'; # Daily or Digest
+            next unless $mus->{$mid}->prop( 'opt_communityjoinemail' ) eq 'D'; # Daily or Digest
         
             my $body = "Dear $mus->{$mid}{user},\n\n" .
                        "Over the past day or so, $row->[1] request(s) to join the \"$cuser\" community have " .
diff -r 1543dbb2b1b3 -r e70d0cbd7897 bin/renameuser.pl
--- a/bin/renameuser.pl	Thu Jun 10 18:44:08 2010 +0800
+++ b/bin/renameuser.pl	Thu Jun 10 18:52:09 2010 +0800
@@ -98,8 +98,8 @@ unless (rename_user("lj_swap_$swapnum", 
 
     # if the fromuser had redirection on, make sure it points to the new $to user
     my $fromu = LJ::load_user($from, 'force');
-    $fromu->preload_props( 'renamedto' ) if $fromu;
-    if ($fromu->{renamedto} && $fromu->{renamedto} ne $to) {
+    my $fromu_r = $fromu ? $fromu->prop( 'renamedto' ) : undef;
+    if ( $fromu_r && $fromu_r ne $to) {
         print "Setting redirection: $from => $to\n";
         unless (LJ::set_userprop($fromu, 'renamedto' => $to)) {
             print "Error setting 'renamedto' userprop for $from\n";
@@ -109,8 +109,7 @@ unless (rename_user("lj_swap_$swapnum", 
 
     # if the $to user had redirection, they shouldn't anymore
     my $tou = LJ::load_user($to, 'force');
-    $tou->preload_props( 'renamedto' ) if $tou;
-    if ($tou->{renamedto}) {
+    if ( $tou && $tou->prop( 'renamedto' ) ) {
         print "Removing redirection for user: $to\n";
         unless (LJ::set_userprop($tou, 'renamedto' => undef)) {
             print "Error setting 'renamedto' userprop for $to\n";
diff -r 1543dbb2b1b3 -r e70d0cbd7897 cgi-bin/Apache/LiveJournal.pm
--- a/cgi-bin/Apache/LiveJournal.pm	Thu Jun 10 18:44:08 2010 +0800
+++ b/cgi-bin/Apache/LiveJournal.pm	Thu Jun 10 18:52:09 2010 +0800
@@ -792,8 +792,7 @@ sub trans
         # under a given username, without sprinkling redirects everywhere.
         my $u = LJ::load_user($user);
         if ( $u && $u->is_redirect && $u->is_renamed ) {
-            $u->preload_props( 'renamedto' );
-            my $renamedto = $u->{'renamedto'};
+            my $renamedto = $u->prop( 'renamedto' );
             if ($renamedto ne '') {
                 my $redirect_url = ($renamedto =~ m!^https?://!) ? $renamedto : LJ::journal_base($renamedto, $vhost) . $uuri . $args_wq;
                 return redir($r, $redirect_url, 301);
diff -r 1543dbb2b1b3 -r e70d0cbd7897 cgi-bin/Apache/LiveJournal/Interface/AtomAPI.pm
--- a/cgi-bin/Apache/LiveJournal/Interface/AtomAPI.pm	Thu Jun 10 18:44:08 2010 +0800
+++ b/cgi-bin/Apache/LiveJournal/Interface/AtomAPI.pm	Thu Jun 10 18:52:09 2010 +0800
@@ -519,8 +519,7 @@ sub handle {
     # TODO: Add communities?
     my $method = $r->method;
     if ( $method eq 'GET' && ! $action ) {
-        $u->preload_props( 'journaltitle' );
-        my $title = $u->{journaltitle} || $u->{user};
+        my $title = $u->prop( 'journaltitle' ) || $u->user;
         my $feed = XML::Atom::Feed->new();
 
         my $add_link = sub {
diff -r 1543dbb2b1b3 -r e70d0cbd7897 cgi-bin/Apache/LiveJournal/Interface/Blogger.pm
--- a/cgi-bin/Apache/LiveJournal/Interface/Blogger.pm	Thu Jun 10 18:44:08 2010 +0800
+++ b/cgi-bin/Apache/LiveJournal/Interface/Blogger.pm	Thu Jun 10 18:52:09 2010 +0800
@@ -235,15 +235,13 @@ sub getUserInfo {
     my $u = LJ::load_user($user) or die "Invalid login\n";
     die "Invalid login\n" unless LJ::auth_okay($u, $password);
 
-    $u->preload_props( "url" );
-
     return {
         'userid' => $u->{'userid'},
         'nickname' => $u->{'user'},
         'firstname' => $u->{'name'},
         'lastname' => $u->{'name'},
         'email' => $u->email_raw,
-        'url' => $u->{'url'},
+        'url' => $u->prop( "url" ),
     };
 }
 
diff -r 1543dbb2b1b3 -r e70d0cbd7897 cgi-bin/LJ/Blob.pm
--- a/cgi-bin/LJ/Blob.pm	Thu Jun 10 18:44:08 2010 +0800
+++ b/cgi-bin/LJ/Blob.pm	Thu Jun 10 18:52:09 2010 +0800
@@ -61,9 +61,8 @@ sub _load_bcid {
     die "No user" unless LJ::isu( $u );
     return $u->{blob_clusterid} if $u->{blob_clusterid};
 
-    $u->preload_props( "blob_clusterid" );
-    return $u->{blob_clusterid} if $u->{blob_clusterid};
-    die "Couldn't find user $u->{user}'s blob_clusterid\n";
+    return $u->prop( "blob_clusterid" )
+        or die "Couldn't find user $u->{user}'s blob_clusterid\n";
 }
 
 # args: u, domain, fmt, bid
diff -r 1543dbb2b1b3 -r e70d0cbd7897 cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm	Thu Jun 10 18:44:08 2010 +0800
+++ b/cgi-bin/LJ/S2.pm	Thu Jun 10 18:52:09 2010 +0800
@@ -3293,9 +3293,8 @@ sub _print_quickreply_link
 
     my $page = get_page();
     my $remote = LJ::get_remote();
-    $remote->preload_props( "opt_no_quickreply" ) if $remote;
     my $onclick = "";
-    unless ($remote->{'opt_no_quickreply'}) {
+    unless ( $remote && $remote->prop( "opt_no_quickreply" ) ) {
         my $pid = (int($target)&&$page->{'_type'} eq 'EntryPage') ? int($target /256) : 0;
 
         $basesubject =~ s/^(Re:\s*)*//i;
diff -r 1543dbb2b1b3 -r e70d0cbd7897 cgi-bin/LJ/Tags.pm
--- a/cgi-bin/LJ/Tags.pm	Thu Jun 10 18:44:08 2010 +0800
+++ b/cgi-bin/LJ/Tags.pm	Thu Jun 10 18:52:09 2010 +0800
@@ -587,11 +587,8 @@ sub get_permission_levels {
     my $u = LJ::want_user(shift);
     return undef unless $u;
 
-    # get the prop
-    $u->preload_props( 'opt_tagpermissions' );
-
     # return defaults for accounts
-    unless ($u->{opt_tagpermissions}) {
+    unless ( $u->prop( 'opt_tagpermissions' ) ) {
         if ( $u->is_community ) {
             # communities are members (trusted) add, private (maintainers) control
             return { add => 'protected', control => 'private' };
diff -r 1543dbb2b1b3 -r e70d0cbd7897 cgi-bin/LJ/Talk.pm
--- a/cgi-bin/LJ/Talk.pm	Thu Jun 10 18:44:08 2010 +0800
+++ b/cgi-bin/LJ/Talk.pm	Thu Jun 10 18:52:09 2010 +0800
@@ -367,9 +367,8 @@ sub screening_level {
     return $val if $val;
 
     # now return userprop, as it's our last chance
-    $journalu->preload_props( 'opt_whoscreened' );
-    return if $journalu->{opt_whoscreened} eq 'N';
-    return $journalu->{opt_whoscreened};
+    my $userprop = $journalu->prop( 'opt_whoscreened' );
+    return $userprop eq 'N' ? undef : $userprop;
 }
 
 sub update_commentalter {
@@ -2532,9 +2531,8 @@ sub mail_comments {
     # they couldn't have posted if they were.  (and if they did somehow, we're just emailing
     # them, so it shouldn't matter.)
     my $u = $comment->{u};
-    $u->preload_props( 'opt_getselfemail' ) if $u;
-    if ($u && $u->{'opt_getselfemail'} && $u->can_get_self_email
-        && !$u->gets_notified(journal => $journalu, arg1 => $ditemid, arg2 => $comment->{talkid})) {
+    if ( $u && $u->prop( 'opt_getselfemail' ) && $u->can_get_self_email
+        && !$u->gets_notified( journal => $journalu, arg1 => $ditemid, arg2 => $comment->{talkid} ) ) {
         my $part;
 
         # Now we going to send email to '$u'.
diff -r 1543dbb2b1b3 -r e70d0cbd7897 cgi-bin/ljemailgateway-web.pl
--- a/cgi-bin/ljemailgateway-web.pl	Thu Jun 10 18:44:08 2010 +0800
+++ b/cgi-bin/ljemailgateway-web.pl	Thu Jun 10 18:52:09 2010 +0800
@@ -26,8 +26,7 @@ sub get_allowed_senders {
     return undef unless LJ::isu( $u );
     my (%addr, @address);
 
-    $u->preload_props( 'emailpost_allowfrom' );
-    @address = split(/\s*,\s*/, $u->{emailpost_allowfrom});
+    @address = split( /\s*,\s*/, $u->prop( 'emailpost_allowfrom' ) );
     return undef unless scalar(@address) > 0;
 
     my %flag_english = ( 'E' => 'get_errors' );
diff -r 1543dbb2b1b3 -r e70d0cbd7897 cgi-bin/ljemailgateway.pl
--- a/cgi-bin/ljemailgateway.pl	Thu Jun 10 18:44:08 2010 +0800
+++ b/cgi-bin/ljemailgateway.pl	Thu Jun 10 18:52:09 2010 +0800
@@ -71,9 +71,6 @@ sub process {
     ($user, $journal) = split(/\./, $user) if $user =~ /\./;
     $u = LJ::load_user($user);
     return unless $u && $u->is_visible;
-
-    $u->preload_props( 'emailpost_pin' )
-        unless lc( $pin ) eq 'pgp' && $LJ::USE_PGP;
 
     # Pick what address to send potential errors to.
     $addrlist = LJ::Emailpost::get_allowed_senders($u);
@@ -184,7 +181,8 @@ sub process {
             unless grep { lc($from) eq lc($_) } keys %$addrlist;
 
         return $err->("Unable to locate your PIN.") unless $pin;
-        return $err->("Invalid PIN.") unless lc($pin) eq lc($u->{emailpost_pin});
+        return $err->("Invalid PIN.")
+            unless lc( $pin ) eq lc( $u->prop( 'emailpost_pin' ) );
     }
 
     return $err->("Email gateway access denied for your account type.")
@@ -607,8 +605,7 @@ sub check_sig {
 sub check_sig {
     my ($u, $entity, $gpg_err) = @_;
 
-    $u->preload_props( 'public_key' ) if LJ::isu( $u );
-    my $key = $u->{public_key};
+    my $key = LJ::isu( $u ) ? $u->prop( 'public_key' ) : undef;
     return 'no_key' unless $key;
 
     # Create work directory.
diff -r 1543dbb2b1b3 -r e70d0cbd7897 cgi-bin/ljprotocol.pl
--- a/cgi-bin/ljprotocol.pl	Thu Jun 10 18:44:08 2010 +0800
+++ b/cgi-bin/ljprotocol.pl	Thu Jun 10 18:52:09 2010 +0800
@@ -134,10 +134,8 @@ sub translate
 sub translate
 {
     my ($u, $msg, $vars) = @_;
-
-    $u->preload_props( "browselang" )
-        unless $u->{'browselang'} || ! LJ::isu( $u );
-    return LJ::Lang::get_text($u->{'browselang'}, "protocol.$msg", undef, $vars);
+    return LJ::Lang::get_text( LJ::isu( $u ) ? $u->prop( "browselang" ) : undef,
+                               "protocol.$msg", undef, $vars );
 }
 
 sub error_class
@@ -1356,8 +1354,7 @@ sub postevent
 
                     next unless $mod->is_visible;
 
-                    $mod->preload_props( 'opt_nomodemail' );
-                    next if $mod->{opt_nomodemail};
+                    next if $mod->prop( 'opt_nomodemail' );
                     next if $mod->{status} ne "A";
 
                     push @emails,
@@ -1878,9 +1875,8 @@ sub editevent
         $qallowmask != $oldevent->{'allowmask'})
     {
         # are they changing their most recent post?
-        $u->preload_props( "newesteventtime" );
-        if ($u->{userid} == $uowner->{userid} &&
-            $u->{newesteventtime} eq $oldevent->{eventtime}) {
+        if ( $u->{userid} == $uowner->{userid} &&
+             $u->prop( "newesteventtime" ) eq $oldevent->{eventtime} ) {
             # did they change the time?
             if ($eventtime ne $oldevent->{eventtime}) {
                 # the newesteventtime is this event's new time.
@@ -2157,10 +2153,9 @@ sub getevents
         # broken client loop prevention
         if ($req->{'lastsync'}) {
             my $pname = "rl_syncitems_getevents_loop";
-            $u->preload_props( $pname );
             # format is:  time/date/time/date/time/date/... so split
             # it into a hash, then delete pairs that are older than an hour
-            my %reqs = split(m!/!, $u->{$pname});
+            my %reqs = split( m!/!, $u->prop( $pname ) );
             foreach (grep { $_ < $now - 60*60 } keys %reqs) { delete $reqs{$_}; }
             my $count = grep { $_ eq $date } values %reqs;
             $reqs{$now} = $date;
diff -r 1543dbb2b1b3 -r e70d0cbd7897 cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl	Thu Jun 10 18:44:08 2010 +0800
+++ b/cgi-bin/weblib.pl	Thu Jun 10 18:52:09 2010 +0800
@@ -676,8 +676,7 @@ sub create_qr_div {
 
     my $qrhtml;
 
-    $remote->preload_props( "opt_no_quickreply" );
-    return undef if $remote->{'opt_no_quickreply'};
+    return undef if $remote->prop( "opt_no_quickreply" );
 
     $qrhtml .= "<div id='qrformdiv'><form id='qrform' name='qrform' method='POST' action='$LJ::SITEROOT/talkpost_do'>";
     $qrhtml .= LJ::form_auth();
@@ -936,8 +935,7 @@ sub make_qr_link
     return undef unless defined $dtid && $linktext && $replyurl;
 
     my $remote = LJ::get_remote();
-    $remote->preload_props( "opt_no_quickreply" ) if $remote;
-    unless ($remote->{'opt_no_quickreply'}) {
+    unless ( $remote && $remote->prop( "opt_no_quickreply" ) ) {
         my $pid = int($dtid / 256);
 
         $basesubject =~ s/^(Re:\s*)*//i;
diff -r 1543dbb2b1b3 -r e70d0cbd7897 htdocs/allpics.bml
--- a/htdocs/allpics.bml	Thu Jun 10 18:44:08 2010 +0800
+++ b/htdocs/allpics.bml	Thu Jun 10 18:52:09 2010 +0800
@@ -92,9 +92,9 @@ _c?>
 
     # redirect renamed users
     if ( $u->is_redirect ) {
-        $u->preload_props( "renamedto" );
-        return BML::redirect("$LJ::SITEROOT/allpics?user=$u->{'renamedto'}")
-            if $u->{'renamedto'};
+        my $renamedto = $u->prop( "renamedto" );
+        return BML::redirect("$LJ::SITEROOT/allpics?user=$renamedto'}")
+            if $renamedto;
     }
 
     my ($can_manage, $getextra);
diff -r 1543dbb2b1b3 -r e70d0cbd7897 htdocs/community/sentinvites.bml
--- a/htdocs/community/sentinvites.bml	Thu Jun 10 18:44:08 2010 +0800
+++ b/htdocs/community/sentinvites.bml	Thu Jun 10 18:52:09 2010 +0800
@@ -93,8 +93,7 @@ body<=
     # columns of our table, excluding username
     my @attribs = ('post');
     my @titleattribs = ('P');
-    $c->preload_props( 'moderated' );
-    if ($c->{moderated}) {
+    if ( $c->prop( 'moderated' ) ) {
         push @attribs, ('preapprove', 'moderate');
         push @titleattribs, ('U', 'M');
     }
diff -r 1543dbb2b1b3 -r e70d0cbd7897 htdocs/feeds/index.bml
--- a/htdocs/feeds/index.bml	Thu Jun 10 18:44:08 2010 +0800
+++ b/htdocs/feeds/index.bml	Thu Jun 10 18:52:09 2010 +0800
@@ -185,8 +185,7 @@ body<=
         $names{$user} = $name;
 
         my $suser = LJ::load_userid( $suserid ) or next;
-        $suser->preload_props( 'url' );
-        $urls{$user} = $suser->{url};
+        $urls{$user} = $suser->prop( 'url' );
 
         # skip suspended/deleted accounts, already watched feeds
         next if $watched{$suserid} || !$suser->is_visible;
diff -r 1543dbb2b1b3 -r e70d0cbd7897 htdocs/manage/pubkey.bml
--- a/htdocs/manage/pubkey.bml	Thu Jun 10 18:44:08 2010 +0800
+++ b/htdocs/manage/pubkey.bml	Thu Jun 10 18:52:09 2010 +0800
@@ -76,7 +76,6 @@ body<=
     }
 
     # Initial page
-    $u->preload_props( qw( public_key ) );
 
     my $ret;
     $ret .= "<?p ";
@@ -98,7 +97,7 @@ body<=
     $ret .= $error if $error;
     $ret .= "<?p $ML{'.pastekey'} p?>\n";
     $ret .= LJ::html_hidden(userid => $u->{userid});
-    my $val = LJ::did_post() ? $POST{'key'} : $u->{'public_key'};
+    my $val = LJ::did_post() ? $POST{'key'} : $u->prop( 'public_key' );
     $ret .= LJ::html_textarea({name=>'key', value=>$val, rows=>20, cols=>70 });
     $ret .= "<br /><br /><?standout ";
     $ret .= LJ::html_submit($ML{'.save'});
diff -r 1543dbb2b1b3 -r e70d0cbd7897 htdocs/talkread.bml
--- a/htdocs/talkread.bml	Thu Jun 10 18:44:08 2010 +0800
+++ b/htdocs/talkread.bml	Thu Jun 10 18:52:09 2010 +0800
@@ -203,12 +203,10 @@ body<=
     #
 
     # See if we should inject QuickReply javascript
-    $remote->preload_props( "opt_no_quickreply" ) if $remote;
-
     LJ::Hooks::run_hooks("need_res_for_journals", $u);
     LJ::need_res( qw( js/thread_expander.js stc/talkpage.css ) );
 
-    if (($remote && !$remote->{'opt_no_quickreply'}) && !$nocomments) {
+    if ( ( $remote && ! $remote->prop( "opt_no_quickreply" ) ) && ! $nocomments ) {
        # quickreply js libs
        LJ::need_res(qw(
                        js/core.js
diff -r 1543dbb2b1b3 -r e70d0cbd7897 htdocs/tools/memories.bml
--- a/htdocs/tools/memories.bml	Thu Jun 10 18:44:08 2010 +0800
+++ b/htdocs/tools/memories.bml	Thu Jun 10 18:52:09 2010 +0800
@@ -91,8 +91,8 @@ _c?>
  my $userid = $u->{'userid'};
 
  if ( $u->is_redirect ) {
-    $u->preload_props( "renamedto" );
-    return BML::redirect("/tools/memories?user=$u->{'renamedto'}$authasarg");
+    my $renamedto = $u->prop( "renamedto" );
+    return BML::redirect( "/tools/memories?user=$renamedto$authasarg" );
  }
 
  $u->preload_props("opt_blockrobots", "adult_content") if $u->is_visible;
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org