fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-02-08 12:47 pm

[dw-free] Enhancements to "find users with similar interests"

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

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

Use methods, instead of querying SQL. Cleaner, and lets us take advantage of
caching.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/DW/Controller/Search/Interests.pm
--------------------------------------------------------------------------------
diff -r c88e621da04a -r b6c639a8bb2d cgi-bin/DW/Controller/Search/Interests.pm
--- a/cgi-bin/DW/Controller/Search/Interests.pm	Mon Feb 07 15:17:09 2011 +0800
+++ b/cgi-bin/DW/Controller/Search/Interests.pm	Tue Feb 08 20:47:29 2011 +0800
@@ -166,20 +166,16 @@ sub interest_handler {
                          { user => $u->ljuser_display } )
             unless @matches;
 
-        # prepare userid => username hash
-        $sth = $dbr->prepare( "SELECT userid, user FROM useridmap WHERE userid IN (" .
-                              join( ",", @matches ) . ")" );
-        $sth->execute;
-        my %username;
-        while ( my ( $id, $name ) = $sth->fetchrow_array ) {
-            $username{$id} = $name;
-        }
+        # load user objects
+        my $users = LJ::load_userids( @matches );
 
         my $count = 1;
         my $data = [];
         foreach my $uid ( @matches ) {
+            my $match_u = $users->{$uid};
+            next unless $match_u && $match_u->is_visible;
             push @$data, { count => $count++,
-                           user  => LJ::ljuser( $username{$uid} ),
+                           user  => $match_u->ljuser_display,
                            magic => sprintf( "%.3f", $magic{$uid} ) };
         }
         $rv->{findsim_u} = $u;
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org