[livejournal] r21036: LJSUP-11087: LJ::Entry: prevent row load...
Committer: vad
LJSUP-11087: LJ::Entry: prevent row loading during object construction by new_from_row methodU trunk/cgi-bin/LJ/Entry.pm
Modified: trunk/cgi-bin/LJ/Entry.pm =================================================================== --- trunk/cgi-bin/LJ/Entry.pm 2012-01-30 06:40:26 UTC (rev 21035) +++ trunk/cgi-bin/LJ/Entry.pm 2012-01-30 07:57:51 UTC (rev 21036) @@ -64,6 +64,7 @@ unless $n_arg && ($n_arg % 2 == 0); my %opts = @_; + my $row = delete $opts{row}; croak("can't supply both anum and ditemid") if defined $opts{anum} && defined $opts{ditemid}; @@ -106,7 +107,11 @@ # no singleton, will load row my $anum = $self->{anum}; # caller supplied anum - __PACKAGE__->preload_rows([ $self ]); + if ($row){ + $self->absorb_row($row); + } else { + __PACKAGE__->preload_rows([ $self ]); + } return undef if $anum and $anum != $self->{anum}; # incorrect anum -> 'no such entry' $self->{ditemid} = $self->{jitemid} * 256 + $self->{anum}; @@ -184,9 +189,10 @@ my %row = @_; my $journalu = LJ::load_userid($row{journalid}); - my $self = $class->new($journalu, jitemid => $row{jitemid}); - $self->absorb_row(\%row); - + my $self = $class->new($journalu, + jitemid => $row{jitemid}, + row => \%row, ## absorb row in the constructor. + ); return $self; }