Skip to content

Commit

Permalink
Fix race condition that sometimes results in the pattern cache gettin…
Browse files Browse the repository at this point in the history
…g corrupted
  • Loading branch information
kraih committed Aug 19, 2024
1 parent 4674d8b commit 129cddd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
3 changes: 1 addition & 2 deletions lib/Cavil/Controller/License.pm
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ sub update_pattern ($self) {
my $pattern = $validation->param('pattern');

# expire old license pattern
$patterns->expire_cache;
my $result = $patterns->update(
$id,
packname => $validation->param('packname'),
Expand All @@ -207,8 +206,8 @@ sub update_pattern ($self) {
$self->flash(danger => 'Conflicting license pattern already exists.');
return $self->redirect_to('edit_pattern', id => $id);
}
$patterns->expire_cache;
$self->packages->mark_matched_for_reindex($id);
$self->app->minion->enqueue(pattern_stats => [] => {priority => 9});
$self->flash(success => 'Pattern has been updated, reindexing all affected packages.');
$self->redirect_to('edit_pattern', id => $id);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Cavil/Model/Patterns.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ sub create ($self, %args) {

$self->expire_cache;

# reclculate the tf-idfs
$self->minion->enqueue(pattern_stats => [] => {priority => 9});

return $self->find($mid);
}

sub expire_cache ($self) {
my $cache = path($self->cache);
unlink $cache->child('cavil.tokens')->to_string;
unlink $cache->child('cavil.pattern.bag')->to_string;

# Reclculate the tf-idfs
$self->minion->enqueue(pattern_stats => [] => {priority => 9});
}

sub has_new_patterns ($self, $packname, $when) {
Expand Down
3 changes: 0 additions & 3 deletions lib/Cavil/Sync.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ sub load ($self, $path) {

$patterns->expire_cache;

# reclculate the tf-idfs
$app->minion->enqueue(pattern_stats => [] => {priority => 9});

return $imported;
}

Expand Down
6 changes: 3 additions & 3 deletions t/index.t
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ subtest 'Pattern change' => sub {
# Automatic reindexing
my $list = $t->app->minion->backend->list_jobs(0, 10, {states => ['inactive']});
is $list->{total}, 2, 'two inactives job';
is $list->{jobs}[0]{task}, 'pattern_stats', 'right task';
is $list->{jobs}[1]{task}, 'reindex_matched_later', 'right task';
is_deeply $list->{jobs}[1]{args}, [1], 'right arguments';
is $list->{jobs}[0]{task}, 'reindex_matched_later', 'right task';
is $list->{jobs}[1]{task}, 'pattern_stats', 'right task';
is_deeply $list->{jobs}[0]{args}, [1], 'right arguments';
my $reindex_id = $list->{jobs}[0]{id};
$t->app->minion->perform_jobs;
is $t->app->minion->job($reindex_id)->info->{state}, 'finished', 'job is finished';
Expand Down

0 comments on commit 129cddd

Please sign in to comment.