From 129cddd8c3ecb02d386d1693f4e3a8103b9d1313 Mon Sep 17 00:00:00 2001 From: Sebastian Riedel Date: Mon, 19 Aug 2024 18:25:24 +0200 Subject: [PATCH] Fix race condition that sometimes results in the pattern cache getting corrupted --- lib/Cavil/Controller/License.pm | 3 +-- lib/Cavil/Model/Patterns.pm | 6 +++--- lib/Cavil/Sync.pm | 3 --- t/index.t | 6 +++--- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/Cavil/Controller/License.pm b/lib/Cavil/Controller/License.pm index 44d3602ee..476bca172 100644 --- a/lib/Cavil/Controller/License.pm +++ b/lib/Cavil/Controller/License.pm @@ -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'), @@ -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); } diff --git a/lib/Cavil/Model/Patterns.pm b/lib/Cavil/Model/Patterns.pm index c29ef33c4..23ff07387 100644 --- a/lib/Cavil/Model/Patterns.pm +++ b/lib/Cavil/Model/Patterns.pm @@ -90,9 +90,6 @@ sub create ($self, %args) { $self->expire_cache; - # reclculate the tf-idfs - $self->minion->enqueue(pattern_stats => [] => {priority => 9}); - return $self->find($mid); } @@ -100,6 +97,9 @@ 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) { diff --git a/lib/Cavil/Sync.pm b/lib/Cavil/Sync.pm index 85ac4994f..9544978eb 100644 --- a/lib/Cavil/Sync.pm +++ b/lib/Cavil/Sync.pm @@ -53,9 +53,6 @@ sub load ($self, $path) { $patterns->expire_cache; - # reclculate the tf-idfs - $app->minion->enqueue(pattern_stats => [] => {priority => 9}); - return $imported; } diff --git a/t/index.t b/t/index.t index 6a3bf6ae5..c429b9888 100644 --- a/t/index.t +++ b/t/index.t @@ -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';