Multiple records of Search::Zoekt::Task with task_type delete_repo
What does this MR do and why?
The problem was for the delete_task
the project
was nil
. So find_or_initialize_by(project: project, zoekt_index: zoekt_index)
was just returning the first found record with the matching zoekt_index
. And then create the delete_repo
tasks on that Repository
. Thats the reason, we saw multiple tasks
records for a specific zoekt_repository
because find_or_initialize_by
was always returning the same record. Now I am passing the project_id
instead of project
because for the delete_repo
tasks project
is nil
.
Since the project
can be nil
in the Search::Zoekt::Repository
, the unique validation of zoekt_index_id
and project_id
is actually not correct. allow: nil
was needed. But instead, I have replaced the validation from project_id
to project_identifier
which is more accurate.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
Enable the feature flag: zoekt_create_indexing_tasks
.
Feature.enable :zoekt_create_indexing_tasks
I recommend setting for a new namespace. If you already have Search::Zoekt::EnabledNamespace
with existing project_id
nil
, then you can actually reproduce the bug even when you delete the first project.
Verify on master
that it is not working.
- Setup Zoekt for a namespace
- Create two projects under the selected root namespace in the first step.
- Verify in the Rails console that the
Search::Zoekt::Repository
records are created for these two projects. - Now delete one of these two projects from the settings or the rails console. If deleting from the settings you have to go to the settings again to delete the project immediately.
- Verify in the Rails console that the
project_id
in theSearch::Zoekt::Repository
for the deleted project isnil
. Also, check that theSearch::Zoekt::Task
record is created with thetask_type
asdelete_repo
for the deleted project. - Now delete the second project also. Verify in the Rails console that the
project_id
in theSearch::Zoekt::Repository
for the deleted project isnil
. Check in the Rails console thatSearch::Zoekt::Task
is created but theproject_identifier
is equal to the first deleted project.
Verify on the branch 450736-backend-for-multiple-matches-in-a-single-file
In the last step the Search::Zoekt::Task
is created but the project_identifier
is equal to the second deleted project.
Related to #467154 (closed)