Skip to content

Commit

Permalink
Merge pull request #528 from open5e/468-deprecate-v1-search
Browse files Browse the repository at this point in the history
468 deprecate v1 search
  • Loading branch information
augustjohnson authored Aug 31, 2024
2 parents 3ea8a1c + 20e71c0 commit f7c50db
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 59 deletions.
46 changes: 25 additions & 21 deletions api/management/commands/quicksetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,42 @@ def add_arguments(self, parser: argparse.ArgumentParser):
)

def handle(self, *args, **options):
"""[TODO] Check if the directory is dirty."""
# Does whoosh_index exist

# Does staticfiles exist
# Does db.sqlite3 exist


"""Main logic."""
self.stdout.write('Migrating the database...')
migrate_db()

self.stdout.write('Collecting static files...')
collect_static()

self.stdout.write('Populating the v1 database...')
import_v1()

if settings.INCLUDE_V1_DATA:
self.stdout.write('Populating the v1 database...')
import_v1()

if not options['noindex']:
if settings.BUILD_V1_INDEX:
build_haystack_index()
else:
self.stdout.write("Skipping v1 index build because of --noindex")
else:
self.stdout.write('Skipping v1 database population.')

if settings.V2_ENABLED:
if settings.INCLUDE_V2_DATA:
self.stdout.write('Populating the v2 database...')
import_v2()

if options["noindex"]:
self.stdout.write('Skipping search index rebuild due to --noindex...')
if not options['noindex']:
if settings.BUILD_V2_INDEX:
self.stdout.write('Building the v2 index with both v1 and v2 data.')
build_v1v2_searchindex()
else:
self.stdout.write('Rebuilding the search index...')
build_haystack_index()

# Flag for v2 enabled decides:
if settings.V2_SEARCH_ENABLED:
if settings.V2_ENABLED:
build_searchindex()
else:
build_v1_searchindex()
self.stdout.write('Skipping v2 index build because of --noindex.')

self.stdout.write(self.style.SUCCESS('API setup complete.'))

Expand Down Expand Up @@ -81,12 +90,7 @@ def build_haystack_index() -> None:
API that is being called, and only applies to v1 data."""
call_command('update_index', '--remove')

def build_v1_searchindex() -> None:
"""Builds the custom search index defined in the api_v2 management
commands. Only adds the v1 data."""
call_command('buildindex', '--v1')

def build_searchindex() -> None:
def build_v1v2_searchindex() -> None:
"""Builds the custom search index defined in the api_v2 management
commands. Only adds the v1 data."""
call_command('buildindex','--v1','--v2')
3 changes: 0 additions & 3 deletions api_v2/management/commands/buildindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ def handle(self, *args, **options):
# Clear out the content table.
self.unload_all_content()

load_v1=False
load_v2=False

if options["v1"]:
# Load the v1 models into the content table.
self.load_content(v1.MagicItem,"v1")
Expand Down
2 changes: 0 additions & 2 deletions api_v2/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,4 @@ def get_queryset(self):
f"SELECT {','.join(columns)} FROM {table_name} WHERE {' AND '.join(filters)} ORDER BY {order_by}",
[schema_version, document_pk, object_model, query])

print(weighted_queryset)

return weighted_queryset
11 changes: 7 additions & 4 deletions server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get("OPEN5E_DEBUG", "") != "False"

# A flag that is True when not production to disallow /v2 api endpoint.
V2_ENABLED = True
# Flags to include v1 data and index.
INCLUDE_V1_DATA = True
BUILD_V1_INDEX = False

# A flag to be set related to v2 search being used for v1 items.
V2_SEARCH_ENABLED = True
# Flags to include v2 data
INCLUDE_V2_DATA = True

# V2 index always includes v1 data (at this time).
BUILD_V2_INDEX = True

# Added as part of the migration from django 2 to django 3.
# Not likely to apply in the short term. https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
Expand Down
58 changes: 29 additions & 29 deletions server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,37 @@


router_v2 = routers.DefaultRouter()
if settings.V2_ENABLED:
router_v2.register(r'items',views_v2.ItemViewSet)
router_v2.register(r'itemsets',views_v2.ItemSetViewSet)
router_v2.register(r'itemcategories',views_v2.ItemCategoryViewSet)
router_v2.register(r'documents',views_v2.DocumentViewSet)
router_v2.register(r'licenses',views_v2.LicenseViewSet)
router_v2.register(r'publishers',views_v2.PublisherViewSet)
router_v2.register(r'weapons',views_v2.WeaponViewSet)
router_v2.register(r'armor',views_v2.ArmorViewSet)
router_v2.register(r'rulesets',views_v2.RulesetViewSet)
router_v2.register(r'backgrounds',views_v2.BackgroundViewSet)
router_v2.register(r'feats',views_v2.FeatViewSet)
router_v2.register(r'races',views_v2.RaceViewSet)
router_v2.register(r'creatures',views_v2.CreatureViewSet)
router_v2.register(r'creaturetypes',views_v2.CreatureTypeViewSet)
router_v2.register(r'creaturesets',views_v2.CreatureSetViewSet)
router_v2.register(r'damagetypes',views_v2.DamageTypeViewSet)
router_v2.register(r'languages',views_v2.LanguageViewSet)
router_v2.register(r'alignments',views_v2.AlignmentViewSet)
router_v2.register(r'conditions',views_v2.ConditionViewSet)
router_v2.register(r'spells',views_v2.SpellViewSet)
router_v2.register(r'classes',views_v2.CharacterClassViewSet)
router_v2.register(r'sizes',views_v2.SizeViewSet)
router_v2.register(r'itemrarities',views_v2.ItemRarityViewSet)
router_v2.register(r'environments',views_v2.EnvironmentViewSet)
router_v2.register(r'abilities',views_v2.AbilityViewSet)
router_v2.register(r'skills',views_v2.SkillViewSet)

router_v2.register(r'items',views_v2.ItemViewSet)
router_v2.register(r'itemsets',views_v2.ItemSetViewSet)
router_v2.register(r'itemcategories',views_v2.ItemCategoryViewSet)
router_v2.register(r'documents',views_v2.DocumentViewSet)
router_v2.register(r'licenses',views_v2.LicenseViewSet)
router_v2.register(r'publishers',views_v2.PublisherViewSet)
router_v2.register(r'weapons',views_v2.WeaponViewSet)
router_v2.register(r'armor',views_v2.ArmorViewSet)
router_v2.register(r'rulesets',views_v2.RulesetViewSet)
router_v2.register(r'backgrounds',views_v2.BackgroundViewSet)
router_v2.register(r'feats',views_v2.FeatViewSet)
router_v2.register(r'races',views_v2.RaceViewSet)
router_v2.register(r'creatures',views_v2.CreatureViewSet)
router_v2.register(r'creaturetypes',views_v2.CreatureTypeViewSet)
router_v2.register(r'creaturesets',views_v2.CreatureSetViewSet)
router_v2.register(r'damagetypes',views_v2.DamageTypeViewSet)
router_v2.register(r'languages',views_v2.LanguageViewSet)
router_v2.register(r'alignments',views_v2.AlignmentViewSet)
router_v2.register(r'conditions',views_v2.ConditionViewSet)
router_v2.register(r'spells',views_v2.SpellViewSet)
router_v2.register(r'classes',views_v2.CharacterClassViewSet)
router_v2.register(r'sizes',views_v2.SizeViewSet)
router_v2.register(r'itemrarities',views_v2.ItemRarityViewSet)
router_v2.register(r'environments',views_v2.EnvironmentViewSet)
router_v2.register(r'abilities',views_v2.AbilityViewSet)
router_v2.register(r'skills',views_v2.SkillViewSet)

router_search = routers.DefaultRouter()
if settings.V2_SEARCH_ENABLED:
router_search.register('',views_v2.SearchResultViewSet, basename='search')

router_search.register('',views_v2.SearchResultViewSet, basename='search')


# Wire up our API using automatic URL routing.
Expand Down

0 comments on commit f7c50db

Please sign in to comment.