-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve index update #645
Draft
CamLamb
wants to merge
6
commits into
main
Choose a base branch
from
improve-index-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,584
−8
Draft
Improve index update #645
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9824d17
Stop calling update_index with --schema-only
CamLamb 27c7442
Add a new method that stores the current index mapping to JSON and ad…
CamLamb 4077357
Update the update_index_async command to only run if the index mappin…
CamLamb 3113e57
Remove bad import
CamLamb 9fd62d5
Fix sorting of the mapping json so it doesn't change each time
CamLamb fa92d79
Remove unused imports
CamLamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/extended_search/management/commands/create_index_mapping_json.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from pathlib import Path | ||
|
||
from django.core.management.base import BaseCommand | ||
from wagtail.search.backends import get_search_backend | ||
|
||
from extended_search.index import get_indexed_models | ||
|
||
|
||
# Path: src/extended_search/management/commands/create_index_fields_json.py | ||
JSON_FILE = Path(__file__).parent / "indexed_mapping.json" | ||
|
||
|
||
def get_indexed_mapping_dict(): | ||
""" | ||
Return a dictionary of indexed models and their fields | ||
Ignoring some models that we don't care about. | ||
""" | ||
|
||
search_backend = get_search_backend() | ||
|
||
return { | ||
str(model): search_backend.mapping_class(model).get_mapping() | ||
for model in get_indexed_models() | ||
} | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Create test JSON containing the mapping for all indexed models" | ||
|
||
def handle(self, *args, **options): | ||
import json | ||
|
||
with open(JSON_FILE, "w") as f: | ||
json.dump(get_indexed_mapping_dict(), f, indent=4) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not currently settled on using the cache for this, but this is just to capture the concept first.
Happy to discuss alternatives as the negative impact of this not being in the cache is higher than "just a longer page load time"