Skip to content

Conversation

@peteeckel
Copy link
Contributor

@peteeckel peteeckel commented Jun 27, 2024

  • Clear all indexes only if neither --lazy nor a list of models are specified for "manage.py reindex"
  • Otherwise, clear the index for a model immediately before rebuilding it

Fixes: #16747

* Clear all indexes only if neither --lazy nor a list of models are
  specified for "manage.py reindex"

* Otherwise, clear the index for a model immediately before rebuilding
  it
if model_labels:
self.stdout.write(f'clearing {cached_count} cached values... ', ending='')
self.stdout.flush()
search_backend.clear(object_types=[content_type])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to keep the cache clearing logic before and separate from the indexing logic. The call to search_backend.clear() above (originally line 73) should be wrapped in a conditional that checks for model_labels and passes either the appropriate content types or None. The indexing logic can then be retained in its original form.

@peteeckel peteeckel requested a review from jeremystretch June 30, 2024 16:14
Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @peteeckel!

@jeremystretch jeremystretch merged commit 753ba5d into netbox-community:develop Jul 1, 2024
@peteeckel peteeckel deleted the 16747-selective-reindexing branch July 1, 2024 13:17
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reindex manage command behaves unexpectedly

2 participants