fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-09-14 07:42 am

[dw-free] cleaning up userpics code

[commit: http://hg.dwscoalition.org/dw-free/rev/d40a6121b525]

http://bugs.dwscoalition.org/show_bug.cgi?id=513

Also be able to retrieve expunged userpics.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/Userpic.pm
--------------------------------------------------------------------------------
diff -r 794521415285 -r d40a6121b525 cgi-bin/LJ/Userpic.pm
--- a/cgi-bin/LJ/Userpic.pm	Tue Sep 14 15:34:17 2010 +0800
+++ b/cgi-bin/LJ/Userpic.pm	Tue Sep 14 15:42:02 2010 +0800
@@ -87,14 +87,21 @@ sub get {
     return unless LJ::isu( $u );
     return if $u->is_expunged;
 
+    my $obj = ref $class ? $class : $class->new( $u, $picid );
     my @cache = $class->load_user_userpics( $u );
 
-    if (@cache) {
-        my $obj = ref $class ? $class : $class->new( $u, $picid );
-        foreach my $curr (@cache) {
+    foreach my $curr ( @cache ) {
             return $obj->absorb_row( $curr ) if $curr->{picid} == $picid;
-        }
     }
+
+    # check the database directly (for expunged userpics,
+    # which aren't included in load_user_userpics)
+    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, $picid );
+    return $obj->absorb_row( $row ) if $row;
 
     return undef;
 }
--------------------------------------------------------------------------------
pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)

[personal profile] pne 2010-09-14 11:40 am (UTC)(link)
I'm a bit amused by the use of "retrieve" and "expunged" in the same sentence - if they can be retrieved, they haven't been expunged very well, have they? :)
kareila: (Default)

[personal profile] kareila 2010-09-14 03:09 pm (UTC)(link)
My understanding is that they've been expunged from MogileFS, and the metadata is retained in MySQL.

But yes, I see the humor. :)