Use newer code path.
Patch by kareila.
diffs (125 lines):
diff -r d30f12d7e883 -r 62e8e4716e81 cgi-bin/LJ/Comment.pm
--- a/cgi-bin/LJ/Comment.pm Wed Sep 08 13:21:45 2010 +0800
+++ b/cgi-bin/LJ/Comment.pm Wed Sep 08 14:21:07 2010 +0800
@@ -1408,18 +1408,11 @@ sub _format_mail_both {
my $pichtml;
my $pic_kw = $self->prop('picture_keyword');
- if ($posteru && $posteru->{defaultpicid} || $pic_kw) {
- my $pic = $pic_kw ? LJ::get_pic_from_keyword($posteru, $pic_kw) :
undef;
- my $picid = $pic ? $pic->{picid} : $posteru->{defaultpicid};
- unless ($pic) {
- my %pics;
- LJ::load_userpics(\%pics, [ $posteru, $posteru->{defaultpicid}
]);
- $pic = $pics{$picid};
- # load_userpics doesn't return picid, but we rely on it above
- $picid = $picid;
- }
- if ($pic) {
- $pichtml = "<img
src=\"$LJ::USERPIC_ROOT/$picid/$pic->{userid}\" align='absmiddle' ".
+ if ( $posteru ) {
+ my $pic = LJ::Userpic->new_from_keyword( $posteru, $pic_kw ) ||
$posteru->userpic;
+
+ if ( $pic && $pic->load_row ) {
+ $pichtml = "<img
src=\"$LJ::USERPIC_ROOT/$pic->{picid}/$pic->{userid}\" align='absmiddle' ".
"width='$pic->{width}' height='$pic->{height}' ".
"hspace='1' vspace='2' alt='' /> ";
}
diff -r d30f12d7e883 -r 62e8e4716e81 cgi-bin/LJ/Userpic.pm
--- a/cgi-bin/LJ/Userpic.pm Wed Sep 08 13:21:45 2010 +0800
+++ b/cgi-bin/LJ/Userpic.pm Wed Sep 08 14:21:07 2010 +0800
@@ -81,14 +81,18 @@ sub instance {
# LJ::Userpic accessor. Returns a LJ::Userpic object indicated by $picid, or
# undef if userpic doesn't exist in the db.
+# TODO: add in lazy peer loading here?
sub get {
- my ($class, $u, $picid) = @_;
+ my ( $class, $u, $picid ) = @_;
+ return unless LJ::isu( $u );
+ return if $u->is_expunged;
- my @cache = LJ::Userpic->load_user_userpics($u);
+ my @cache = $class->load_user_userpics( $u );
if (@cache) {
+ my $obj = ref $class ? $class : $class->new( $u, $picid );
foreach my $curr (@cache) {
- return LJ::Userpic->new( $u, $curr->{picid} ) if $curr->{picid} ==
$picid;
+ return $obj->absorb_row( $curr ) if $curr->{picid} == $picid;
}
}
@@ -272,13 +276,9 @@ sub dimensions {
# width and height probably loaded from DB
return ($self->{width}, $self->{height}) if ($self->{width} &&
$self->{height});
- my %upics;
- my $u = LJ::load_userid($self->{userid});
- LJ::load_userpics(\%upics, [ $u, $self->{picid} ]);
- my $up = $upics{$self->{picid}} or
- return ();
-
- return ($up->{width}, $up->{height});
+ # if not, load them explicitly
+ $self->load_row;
+ return ( $self->{width}, $self->{height} );
}
sub max_allowed_bytes {
@@ -488,30 +488,12 @@ sub imagedata {
return $data ? $data : undef;
}
-# TODO: add in lazy peer loading here
+# get : class :: load_row : object
sub load_row {
my $self = shift;
- my $u = $self->owner;
- return unless defined $u;
- return if $u->is_expunged;
- # Load all of the userpics from cache, or load them from the database and
write them to cache
- my @cache = LJ::Userpic->load_user_userpics($u);
-
- if (@cache) {
- foreach my $curr (@cache) {
- return $self->absorb_row($curr) if $curr->{picid} eq $self->picid;
- }
- }
-
- # If you get past this conditional something is wrong
- # load_user_userpics always returns a value
-
- my $row = $u->selectrow_hashref( "SELECT userid, picid, width, height,
state, fmt, comment, description, location, url, " .
- "UNIX_TIMESTAMP(picdate) AS 'pictime',
flags, md5base64 " .
- "FROM userpic2 WHERE userid=? AND
picid=?", undef,
- $u->userid, $self->{picid} );
- $self->absorb_row($row) if $row;
+ # use class method
+ return $self->get( $self->owner, $self->picid );
}
# checks request cache and memcache,
@@ -576,10 +558,10 @@ sub load_user_userpics {
my $cache = $class->get_cache($u);
return @$cache if $cache;
- # select all of their userpics and iterate through them
+ # select all of their userpics
my $data = $u->selectall_hashref(
"SELECT userid, picid, width, height, state, fmt, comment," .
- " description, location, UNIX_TIMESTAMP(picdate) AS 'pictime'," .
+ " description, location, url, UNIX_TIMESTAMP(picdate) AS 'pictime'," .
" flags, md5base64 FROM userpic2 WHERE userid=? AND state <> 'X'",
'picid', undef, $u->userid );
die "Error loading userpics: clusterid=$u->{clusterid}, errstr=" .
$u->errstr
@@ -590,7 +572,7 @@ sub load_user_userpics {
# set cache if reasonable
$class->set_cache($u, \...@ret);
- return map { LJ::Userpic->new_from_row($_) } @ret;
+ return map { $class->new_from_row($_) } @ret;
}
sub create {
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog