[dw-free] migrate LJ::set_userprop to $u->set_prop
[commit: http://hg.dwscoalition.org/dw-free/rev/19acdc22dbb0]
http://bugs.dwscoalition.org/show_bug.cgi?id=2657
Check whether to update the DB inside the function, instead of passing it in
as an argument.
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2657
Check whether to update the DB inside the function, instead of passing it in
as an argument.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- cgi-bin/LJ/User.pm
- htdocs/manage/profile/index.bml
-------------------------------------------------------------------------------- diff -r 601b1915a5ba -r 19acdc22dbb0 cgi-bin/LJ/User.pm --- a/cgi-bin/LJ/User.pm Mon Jul 05 15:47:29 2010 +0800 +++ b/cgi-bin/LJ/User.pm Mon Jul 05 16:04:46 2010 +0800 @@ -7397,19 +7397,15 @@ sub modify_caps { # name: LJ::set_userprop # des: Sets/deletes a userprop by name for a user. # info: This adds or deletes from the -# [dbtable[userprop]]/[dbtable[userproplite]] tables. One -# crappy thing about this interface is that it doesn't allow -# a batch of userprops to be updated at once, which is the -# common thing to do. -# args: dbarg?, uuserid, propname, value, memonly? +# [dbtable[userprop]]/[dbtable[userproplite]] tables. +# args: uuserid, propname, value # des-uuserid: The userid of the user or a user hashref. # des-propname: The name of the property. Or a hashref of propname keys and corresponding values. # des-value: The value to set to the property. If undefined or the # empty string, then property is deleted. -# des-memonly: if true, only writes to memcache, and not to database. # </LJFUNC> sub set_userprop { - my ($u, $propname, $value, $memonly) = @_; + my ( $u, $propname, $value ) = @_; $u = ref $u ? $u : LJ::load_userid($u); my $userid = $u->userid + 0; @@ -7437,7 +7433,8 @@ sub set_userprop { elsif ( $p->{'cldversion'} && $u->dversion >= $p->{'cldversion'} ) { $table = "userproplite2"; } - unless ($memonly) { + unless ( $hash->{$propname} eq $u->{$propname} ) { + # only update db if value has changed my $db = $action{$table}->{'db'} ||= ( $table !~ m{userprop(lite2|blob)} ? LJ::get_db_writer() diff -r 601b1915a5ba -r 19acdc22dbb0 htdocs/manage/profile/index.bml --- a/htdocs/manage/profile/index.bml Mon Jul 05 15:47:29 2010 +0800 +++ b/htdocs/manage/profile/index.bml Mon Jul 05 16:04:46 2010 +0800 @@ -703,12 +703,13 @@ body<= if $u->gizmo_account ne $POST{'gizmo'}; # set userprops + my %prop; foreach my $uprop (@uprops) { my $eff_val = $POST{$uprop}; # effective value, since 0 isn't stored $eff_val = "" unless $eff_val; - my $mem_only = $eff_val eq $u->{$uprop}; - LJ::set_userprop($u, $uprop, $eff_val, $mem_only); + $prop{$uprop} = $eff_val; } + $u->set_prop( \%prop ); # location or bday could've changed... (who cares about checking exactly) $u->invalidate_directory_record; --------------------------------------------------------------------------------