Memcache url->uid map so we don't have to hit the database every time
we load an OpenID user.
Patch by afuna.
diffs (38 lines):
diff -r 2551d07032c7 -r defc0a54946f cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm Wed Jul 22 02:29:27 2009 +0000
+++ b/cgi-bin/LJ/User.pm Wed Jul 22 02:33:46 2009 +0000
@@ -5714,13 +5714,32 @@ sub load_user_or_identity {
# return undef if not dot in arg (can't be a URL)
return undef unless $arg =~ /\./;
- my $dbh = LJ::get_db_writer();
my $url = lc($arg);
$url = "http://$url" unless $url =~ m!^http://!;
$url .= "/" unless $url =~ m!/$!;
+
+ # get from memcache
+ {
+ # overload the uidof memcache key to accept both display name and name
+ my $uid = LJ::MemCache::get( "uidof:$url" );
+ my $u = LJ::memcache_get_u( [ $uid, "userid:$uid" ] ) if $uid;
+ return _set_u_req_cache( $u ) if $u;
+ }
+
+ my $dbh = LJ::get_db_writer();
my $uid = $dbh->selectrow_array("SELECT userid FROM identitymap WHERE
idtype=? AND identity=?",
undef, 'O', $url);
- return LJ::load_userid($uid) if $uid;
+
+ my $u = LJ::load_userid($uid) if $uid;
+
+ # set user in memcache
+ if ( $u ) {
+ # memcache URL-to-userid for identity users
+ LJ::MemCache::set( "uidof:$url", $uid, 1800 );
+ LJ::memcache_set_u( $u );
+ return _set_u_req_cache( $u );
+ }
+
return undef;
}
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog