Breathe new life into LJ::get_interest() and make it respect memcache.
Patch by kareila.
diffs (51 lines):
diff -r cc157cc361f6 -r 85ffb9b478db cgi-bin/ljlib.pl
--- a/cgi-bin/ljlib.pl Mon Oct 26 02:32:34 2009 +0000
+++ b/cgi-bin/ljlib.pl Mon Oct 26 02:43:16 2009 +0000
@@ -1509,15 +1509,24 @@ sub cmd_buffer_add
sub get_interest {
- my $intid = shift
- or return undef;
+ my $intid = shift;
+ return undef unless $intid && $intid =~ /^\d+$/;
+ my ( $int, $intcount );
- # FIXME: caching!
+ my $memkey = [$intid, "introw:$intid"];
+ my $cached = LJ::MemCache::get( $memkey );
+ # memcache row is of form [$intid, $int, $intcount];
- my $dbr = LJ::get_db_reader();
- my ($int, $intcount) = $dbr->selectrow_array
- ("SELECT interest, intcount FROM interests WHERE intid=?",
- undef, $intid);
+ if ( $cached && ref $cached eq 'ARRAY' ) {
+ ( $intid, $int, $intcount ) = @$cached;
+ } else {
+ my $dbr = LJ::get_db_reader();
+ ( $int, $intcount ) =
+ $dbr->selectrow_array( "SELECT interest, intcount FROM interests
WHERE intid=?",
+ undef, $intid );
+ die $dbr->errstr if $dbr->err;
+ LJ::MemCache::set( $memkey, [$intid, $int, $intcount], 3600*12 );
+ }
return wantarray() ? ($int, $intcount) : $int;
}
diff -r cc157cc361f6 -r 85ffb9b478db htdocs/interests.bml
--- a/htdocs/interests.bml Mon Oct 26 02:32:34 2009 +0000
+++ b/htdocs/interests.bml Mon Oct 26 02:43:16 2009 +0000
@@ -82,11 +82,9 @@ body<=
# force them to either come from the interests page, or have posted
the request.
# if both fail, ask them to confirm with a post form.
- my $dbr = LJ::get_db_reader();
-
unless ( $did_post || LJ::check_referer('/interests.bml') )
{
- my ($int) = $dbr->selectrow_array("SELECT interest FROM interests
WHERE intid=?", undef, $intid);
+ my $int = LJ::get_interest( $intid );
LJ::text_out(\$int);
$ret .= "<?h1 $ML{'.add.confirm.head'} h1?>";
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog