Committer: akanashin
LJSUP-13687: 1. New message. Inbox ?\226?\128?\148 DraftU trunk/cgi-bin/LJ/User.pm U trunk/htdocs/tools/endpoints/draft.bml
Modified: trunk/cgi-bin/LJ/User.pm =================================================================== --- trunk/cgi-bin/LJ/User.pm 2012-09-18 12:19:31 UTC (rev 22918) +++ trunk/cgi-bin/LJ/User.pm 2012-09-18 12:38:24 UTC (rev 22919) @@ -3115,9 +3115,12 @@ } sub set_draft_text { - my ($u, $draft) = @_; - my $old = $u->draft_text; + my ($u, $draft, $prop_name) = @_; + $prop_name ||= 'entry_draft'; + + my $old = $u->draft_text($prop_name); + $LJ::_T_DRAFT_RACE->() if $LJ::_T_DRAFT_RACE; # try to find a shortcut that makes the SQL shorter @@ -3126,7 +3129,7 @@ # one method is just setting it all at once. which incurs about # 75 bytes of SQL overhead on top of the length of the draft, # not counting the escaping - push @methods, [ "set", sub { $u->set_prop('entry_draft', $draft); 1 }, + push @methods, [ "set", sub { $u->set_prop($prop_name, $draft); 1 }, 75 + length $draft ]; # stupid case, setting the same thing: @@ -3136,11 +3139,11 @@ if (length $old && $draft =~ /^\Q$old\E(.+)/s) { my $new = $1; my $appending = sub { - my $prop = LJ::get_prop("user", "entry_draft") or die; # FIXME: use exceptions + my $prop = LJ::get_prop("user", $prop_name) or die; # FIXME: use exceptions my $rv = $u->do("UPDATE userpropblob SET value = CONCAT(value, ?) WHERE userid=? AND upropid=? AND LENGTH(value)=?", undef, $new, $u->{userid}, $prop->{id}, length $old); return 0 unless $rv > 0; - $u->uncache_prop("entry_draft"); + $u->uncache_prop($prop_name); return 1; }; push @methods, [ "append", $appending, 40 + length $new ]; @@ -3161,8 +3164,9 @@ } sub draft_text { - my ($u) = @_; - return $u->prop('entry_draft'); + my ($u, $prop_name) = @_; + $prop_name ||= 'entry_draft'; + return $u->prop($prop_name); } sub notable_interests { Modified: trunk/htdocs/tools/endpoints/draft.bml =================================================================== --- trunk/htdocs/tools/endpoints/draft.bml 2012-09-18 12:19:31 UTC (rev 22918) +++ trunk/htdocs/tools/endpoints/draft.bml 2012-09-18 12:38:24 UTC (rev 22919) @@ -21,14 +21,15 @@ } my $ret = {}; + my $prop_name = delete $POST{'prop_name'} || 'entry_draft'; my $draft = delete $POST{'saveDraft'}; if ( defined $draft ) { - $u->set_draft_text(encode($draft)); + $u->set_draft_text(encode($draft), $prop_name); } elsif ( $POST{'clearDraft'} ) { - $u->set_draft_text(''); + $u->set_draft_text('', $prop_name); } else { - my $decoded = decode($u->draft_text); + my $decoded = decode($u->draft_text($prop_name)); if ( ref $decoded ) { %$ret = (%$ret, %$decoded); } else {