Back out some changes; patch causes issues with uploading when mogile 
is enabled. 

diffs (140 lines):

diff -r 3ec41422a3f8 -r 4fd0c9ead3b3 cgi-bin/Apache/LiveJournal.pm
--- a/cgi-bin/Apache/LiveJournal.pm     Tue Sep 07 17:39:56 2010 +0800
+++ b/cgi-bin/Apache/LiveJournal.pm     Tue Sep 07 18:39:10 2010 +0800
@@ -1136,7 +1136,10 @@ sub userpic_content
     my $u = LJ::load_userid($userid);
     return NOT_FOUND unless $u && ! ( $u->is_expunged || $u->is_suspended );
 
-    my $pic = LJ::Userpic->get( $u, $picid ) or return NOT_FOUND;
+    my %upics;
+    LJ::load_userpics(\%upics, [ $u, $picid ]);
+    my $pic = $upics{$picid} or return NOT_FOUND;
+    return NOT_FOUND if $pic->{'userid'} != $userid || $pic->{state} eq 'X';
 
     # Read the mimetype from the pichash if dversion 7
     $mime = { 'G' => 'image/gif',
diff -r 3ec41422a3f8 -r 4fd0c9ead3b3 cgi-bin/LJ/Comment.pm
--- a/cgi-bin/LJ/Comment.pm     Tue Sep 07 17:39:56 2010 +0800
+++ b/cgi-bin/LJ/Comment.pm     Tue Sep 07 18:39:10 2010 +0800
@@ -1408,11 +1408,18 @@ sub _format_mail_both {
         my $pichtml;
         my $pic_kw = $self->prop('picture_keyword');
 
-        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' ".
+        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' ".
                     "width='$pic->{width}' height='$pic->{height}' ".
                     "hspace='1' vspace='2' alt='' /> ";
             }
diff -r 3ec41422a3f8 -r 4fd0c9ead3b3 cgi-bin/LJ/Userpic.pm
--- a/cgi-bin/LJ/Userpic.pm     Tue Sep 07 17:39:56 2010 +0800
+++ b/cgi-bin/LJ/Userpic.pm     Tue Sep 07 18:39:10 2010 +0800
@@ -81,18 +81,14 @@ 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 ) = @_;
-    return unless LJ::isu( $u );
-    return if $u->is_expunged;
+    my ($class, $u, $picid) = @_;
 
-    my @cache = $class->load_user_userpics( $u );
+    my @cache = LJ::Userpic->load_user_userpics($u);
 
     if (@cache) {
-        my $obj = ref $class ? $class : $class->new( $u, $picid );
         foreach my $curr (@cache) {
-            return $obj->absorb_row( $curr ) if $curr->{picid} == $picid;
+            return LJ::Userpic->new( $u, $curr->{picid} ) if $curr->{picid} == 
$picid;
         }
     }
 
@@ -276,9 +272,13 @@ sub dimensions {
     # width and height probably loaded from DB
     return ($self->{width}, $self->{height}) if ($self->{width} && 
$self->{height});
 
-    # if not, load them explicitly
-    $self->load_row;
-    return ( $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});
 }
 
 sub max_allowed_bytes {
@@ -488,12 +488,30 @@ sub imagedata {
     return $data ? $data : undef;
 }
 
-# get : class :: load_row : object
+# TODO: add in lazy peer loading here
 sub load_row {
     my $self = shift;
+    my $u = $self->owner;
+    return unless defined $u;
+    return if $u->is_expunged;
 
-    # use class method
-    return $self->get( $self->owner, $self->picid );
+    # 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;
 }
 
 # checks request cache and memcache,
@@ -558,10 +576,10 @@ sub load_user_userpics {
     my $cache = $class->get_cache($u);
     return @$cache if $cache;
 
-    # select all of their userpics
+    # select all of their userpics and iterate through them
     my $data = $u->selectall_hashref(
         "SELECT userid, picid, width, height, state, fmt, comment," .
-        " description, location, url, UNIX_TIMESTAMP(picdate) AS 'pictime'," .
+        " description, location, 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
@@ -572,7 +590,7 @@ sub load_user_userpics {
     # set cache if reasonable
     $class->set_cache($u, \...@ret);
 
-    return map { $class->new_from_row($_) } @ret;
+    return map { LJ::Userpic->new_from_row($_) } @ret;
 }
 
 sub create {
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to