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

[dw-free] Memcache domain mapping

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

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

Look up the normalized domain name (without "www"); fix a potential 500
error if the domain forwarding isn't set up.

Patch by [personal profile] exor674.

Files modified:
  • cgi-bin/Apache/LiveJournal.pm
--------------------------------------------------------------------------------
diff -r 3cdffb065206 -r 539774793470 cgi-bin/Apache/LiveJournal.pm
--- a/cgi-bin/Apache/LiveJournal.pm	Tue May 25 12:58:53 2010 +0800
+++ b/cgi-bin/Apache/LiveJournal.pm	Tue May 25 13:07:54 2010 +0800
@@ -895,21 +895,20 @@ sub trans
         $host =~ /[^\d\.]/)
     {
         my $dbr = LJ::get_db_reader();
-        my $checkhost = lc($host);
+        my $checkhost = lc( $host );
         $checkhost =~ s/^www\.//i;
-        $checkhost = $dbr->quote($checkhost);
-        my $key = "domain:$host";
-        my $userid = LJ::MemCache::get($key);
+        my $key = "domain:$checkhost";
+        my $userid = LJ::MemCache::get( $key );
         unless (defined $userid) {
             my $db = LJ::get_db_reader();
-            ($userid) = $db->selectrow_array(qq{SELECT userid FROM domains WHERE domain=?}, undef, $host);
+            ($userid) = $db->selectrow_array( qq{SELECT userid FROM domains WHERE domain=?}, undef, $checkhost );
             $userid ||= 0; ## we do cache negative results - if no user for such domain, set userid=0
-            LJ::MemCache::set($key, $userid);
+            LJ::MemCache::set( $key, $userid );
         }
-        my $user = LJ::load_userid($userid)->user;
+        my $user = LJ::load_userid( $userid );
         return 404 unless $user;
 
-        my $view = $determine_view->($user, "other:$host$hostport", $uri);
+        my $view = $determine_view->( $user->user, "other:$host$hostport", $uri );
         return $view if defined $view;
         return 404;
     }
--------------------------------------------------------------------------------