wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[livejournal] r15280: LJINT-272.

Committer: wisest-owl
LJINT-272.


U   trunk/cgi-bin/LJ/Setting/DomainMapping.pm
U   trunk/cgi-bin/LJ/User.pm
U   trunk/htdocs/manage/domain.bml
Modified: trunk/cgi-bin/LJ/Setting/DomainMapping.pm
===================================================================
--- trunk/cgi-bin/LJ/Setting/DomainMapping.pm	2009-06-11 04:05:30 UTC (rev 15279)
+++ trunk/cgi-bin/LJ/Setting/DomainMapping.pm	2009-06-11 06:13:34 UTC (rev 15280)
@@ -28,6 +28,7 @@
     # Blank domain = delete mapping
     if ($domainname eq "") {
         $dbh->do("DELETE FROM domains WHERE userid=?", undef, $u->{userid});
+        LJ::MemCache::delete("domain:" . $u->prop("journaldomain")); 
         $u->set_prop("journaldomain", "");
     # If they're able to, change the mapping and update the userprop
     } elsif ($has_cap) {
@@ -42,6 +43,7 @@
             }
         }
         $u->set_prop("journaldomain", $domainname);
+        LJ::MemCache::set("domain:$domainname", $u->{userid}); 
         if ($u->prop('journaldomain')) {
             $dbh->do("DELETE FROM domains WHERE userid=? AND domain <> ?",
                      undef, $u->{'userid'}, $domainname);

Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm	2009-06-11 04:05:30 UTC (rev 15279)
+++ trunk/cgi-bin/LJ/User.pm	2009-06-11 06:13:34 UTC (rev 15280)
@@ -278,6 +278,21 @@
         return LJ::load_user($1);
     }
 
+    # domains like 'http://news.independent.livejournal.com' or 'http://some.site.domain.com'
+    if ($url =~ m!^http://([\w.-]+)/?$!) {
+        my $host = $1;
+        my $expire = time() + 1800;
+        my $key = "domain:$host";
+        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 ||= 0; ## we do cache negative results - if no user for such domain, set userid=0
+            LJ::MemCache::set($key, $userid, $expire);
+        }
+        return ($userid) ? LJ::load_userid($userid) : undef;
+    }
+
     # subdomains that hold a bunch of users (eg, users.siteroot.com/username/)
     if ($url =~ m!^http://\w+\.\Q$LJ::USER_DOMAIN\E/([\w-]+)/?$!) {
         return LJ::load_user($1);
@@ -5679,7 +5694,7 @@
 
     $user = LJ::canonical_username($user);
     return undef unless length $user;
-
+    
     my $get_user = sub {
         my $use_dbh = shift;
         my $db = $use_dbh ? LJ::get_db_writer() : LJ::get_db_reader();
@@ -5694,9 +5709,9 @@
 
     # caller is forcing a master, return now
     return $get_user->("master") if $force || $LJ::_PRAGMA_FORCE_MASTER;
-
+    
     my $u;
-
+ 
     # return process cache if we have one
     if ($u = $LJ::REQ_CACHE_USER_NAME{$user}) {
         $u->selfassert;

Modified: trunk/htdocs/manage/domain.bml
===================================================================
--- trunk/htdocs/manage/domain.bml	2009-06-11 04:05:30 UTC (rev 15279)
+++ trunk/htdocs/manage/domain.bml	2009-06-11 06:13:34 UTC (rev 15280)
@@ -57,6 +57,7 @@
             my $dom = lc($POST{'journaldomain'});
             if (($dom_cap && !$dom) || (!$dom_cap && $POST{'journaldomain_del'})) {
                 $dbh->do("DELETE FROM domains WHERE userid=?", undef, $u->{'userid'});
+                LJ::MemCache::delete("domain:" . $dom); 
             } else {
                 $dbh->do("INSERT INTO domains VALUES (?, ?)", undef, $dom, $u->{'userid'});
                 if ($dbh->err) {
@@ -68,6 +69,7 @@
                     $dbh->do("DELETE FROM domains WHERE userid=? AND domain <> ?",
                              undef, $u->{'userid'}, $dom);
                 }
+                LJ::MemCache::set("domain:$dom", $u->{userid}); 
             }
 
             # set journaldomain prop if it's been changed

Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments