Skip to content

Commit

Permalink
FireHose memcached bugfix
Browse files Browse the repository at this point in the history
If firehose_mcd_disp was set to false, in some cases, firehose data
was not being properly expired even for non-display uses.  This was
causing problems for the tagbox that set a hose item to is_spam=yes
and then immediately recalculated its score:  the old is_spam=no
value was being retrieved from memcached so its score did not change.

Also, moved a hardcoded expiration time into a var.
  • Loading branch information
jamiemccarthy committed Sep 25, 2008
1 parent 7dc18c8 commit 85b9735
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
34 changes: 18 additions & 16 deletions plugins/FireHose/FireHose.pm
Expand Up @@ -1921,13 +1921,10 @@ sub setFireHose {
}
}

if ($mcd && $constants->{firehose_mcd_disp}) {
$mcd->delete("$mcdkey:$id", 3);
my $keys = $self->genFireHoseMCDAllKeys($id);
foreach (@$keys) {
$mcd->delete($_, 3);
}

if ($mcd) {
$mcd->delete("$mcdkey:$id", 3);
my $keys = $self->genFireHoseMCDAllKeys($id);
$mcd->delete($_, 3) for @$keys;
}

my $searchtoo = getObject('Slash::SearchToo');
Expand All @@ -1944,7 +1941,7 @@ sub setFireHose {

# This generates the key for memcaching dispFireHose results
# if no key is returned no caching or fetching from cache will
# take place
# take place in dispFireHose.

sub genFireHoseMCDKey {
my($self, $id, $options) = @_;
Expand All @@ -1956,21 +1953,25 @@ sub genFireHoseMCDKey {
my $mcd = $self->getMCD();
my $mcdkey;

return if $gSkin->{skid} != $constants->{mainpage_skid};
return if !$constants->{firehose_mcd_disp};
return '' if $gSkin->{skid} != $constants->{mainpage_skid};
return '' if !$constants->{firehose_mcd_disp};

if ($mcd && !$options->{nodates} && !$options->{nobylines} && !$options->{nocolors} && !$options->{nothumbs} && !$form->{skippop} && !$form->{index} && !$options->{vote} && !$user->{is_admin}) {
if ($mcd
&& !$options->{nodates} && !$options->{nobylines} && !$options->{nocolors}
&& !$options->{nothumbs} && !$options->{vote}
&& !$form->{skippop} && !$form->{index}
&& !$user->{is_admin}) {
$mcdkey = "$self->{_mcd_keyprefix}:dispfirehose-$options->{mode}:$id";
}
return $mcdkey;

}

sub genFireHoseMCDAllKeys {
my($self, $id) = @_;
my $keys = [];
my $constants = getCurrentStatic();
return [ ] if !$constants->{firehose_mcd_disp};
my $keys = [ ];
my $mcd = $self->getMCD();
my $mcdkey;
if ($mcd) {
foreach my $mode (qw(full fulltitle)) {
push @$keys, "$self->{_mcd_keyprefix}:dispfirehose-$mode:$id";
Expand All @@ -1979,9 +1980,9 @@ sub genFireHoseMCDAllKeys {
return $keys;
}


sub dispFireHose {
my($self, $item, $options) = @_;
my $constants = getCurrentStatic();
$options ||= {};
my $mcd = $self->getMCD();
my $mcdkey;
Expand Down Expand Up @@ -2010,7 +2011,8 @@ sub dispFireHose {
if ($mcd) {
$mcdkey = $self->genFireHoseMCDKey($item->{id}, $options);
if ($mcdkey) {
$mcd->set($mcdkey, $retval, 180);
my $exptime = $constants->{firehose_memcached_disp_exptime} || 180;
$mcd->set($mcdkey, $retval, $exptime);
}
}
return $retval;
Expand Down
1 change: 1 addition & 0 deletions plugins/FireHose/mysql_dump.sql
Expand Up @@ -29,6 +29,7 @@ INSERT INTO vars (name, value, description) VALUES ('firehose_adminudcclout', '0
INSERT INTO vars (name, value, description) VALUES ('firehose_adminupclout', '0.5', 'Admin clout for upvotes can be reduced by specifying a number between 0 and 1');
INSERT INTO vars (name, value, description) VALUES ('firehose_story_ignore_skids', '', 'list of skids that you want to not want created or shown as firehose entries. Delimit skids with |');
INSERT INTO vars (name, value, description) VALUES ('firehose_color_slices', '30|30|0.2|0.2|0.2|0.2|0.2|0.0', 'Number or percent of remaining stories at each color level separated by | 30|0.5|0.5 would mean 30 stories at the level of highest popularity and 50% at each of remainining stories at the next 2 levels');
INSERT INTO vars (name, value, description) VALUES ('firehose_memcached_disp_exptime', '180', 'Seconds to cache firehose display');
INSERT INTO vars (name, value, description) VALUES ('firehose_memcached_exptime', '600', 'Seconds to cache firehose data generally');
INSERT INTO vars (name, value, description) VALUES ('firehose_slice_points', '290,240 220,200 185,175 155,138 102,93 30,25 0,-20 -60,-999999', 'Seven pairs of numbers: the entry score and minimum score for each color slice (last min should be large negative)');
INSERT INTO vars (name, value, description) VALUES ('firehose_spam_score', '-50', 'Popularity score assigned to all firehose items with is_spam=yes');
Expand Down
7 changes: 3 additions & 4 deletions sql/mysql/upgrades
Expand Up @@ -5522,19 +5522,15 @@ INSERT INTO vars (name, value, description) VALUES ('metamod_use_firehose', '0',
INSERT INTO user_event_types VALUES (4, 'Bookmarks');
INSERT INTO user_event_types VALUES (5, 'Friends');


# 2008-09-11
UPDATE vars SET value = 'T_2_5_0_220' WHERE name = 'cvs_tag_currentcode';


# For plugins/FireHose
INSERT INTO css (rel, type, media, file, title, skin, page, admin, theme, ctid, ordernum, ie_cond) VALUES ('stylesheet','text/css','screen, projection','firehose.css','','','index2','no','',2,0, '');


# 2008-09-17
UPDATE vars SET value = 'T_2_5_0_221' WHERE name = 'cvs_tag_currentcode';


# PUDGE LAST UPDATED HERE

# SLASHCODE/USEPERL LAST UPDATED HERE
Expand All @@ -5543,3 +5539,6 @@ UPDATE vars SET value = 'T_2_5_0_221' WHERE name = 'cvs_tag_currentcode';

INSERT INTO vars (name, value, description) VALUES ('index_new_user_beta', '0', 'Use index beta for new users?');

# For plugins/FireHose
INSERT INTO vars (name, value, description) VALUES ('firehose_memcached_disp_exptime', '180', 'Seconds to cache firehose display');

0 comments on commit 85b9735

Please sign in to comment.