Skip to content

Commit

Permalink
Merge pull request #25 from l0rb/master
Browse files Browse the repository at this point in the history
Change loading time
  • Loading branch information
interrogator committed Dec 3, 2019
2 parents b916e31 + e5ffb2a commit ae59990
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
30 changes: 14 additions & 16 deletions explorer/parts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ def _get_corpora(corpus_meta):
return corpora, tables, corpora_config


# this is a workaround to stop migrate.py from loading corpora.
# if you don't want to load corpora, comment out the call to _get_corpora_meta.
# if you do want to load corpora, leave it uncommented.
# CORPUS_META = dict()
CORPUS_META = _get_corpora_meta(GLOBAL_CONFIG.get("corpora_file"))

CORPORA, INITIAL_TABLES, CORPORA_CONFIGS = _get_corpora(CORPUS_META)


def load_layout(slug, set_and_register=True):
"""
Django can import this function to set the correct dataset on explore page
Expand All @@ -94,10 +85,17 @@ def load_layout(slug, set_and_register=True):
return app


# this can potentially save time: generate layouts for all datasets
# before the pages are visited. comes at expense of some memory,
# but the app should obviously be able to handle all datasets in use
if GLOBAL_CONFIG["load_layouts"]:
for corpus in CORPUS_META:
if not corpus.disabled:
load_layout(corpus.slug, set_and_register=False)
def load_corpora():
global CORPUS_META, CORPORA, INITIAL_TABLES, CORPORA_CONFIGS

CORPUS_META = _get_corpora_meta(GLOBAL_CONFIG.get("corpora_file"))
CORPORA, INITIAL_TABLES, CORPORA_CONFIGS = _get_corpora(CORPUS_META)

# this can potentially save time: generate layouts for all datasets
# before the pages are visited. comes at expense of some memory,
# but the app should obviously be able to handle all datasets in use
if GLOBAL_CONFIG["load_layouts"]:
for corpus in CORPUS_META:
if not corpus.disabled:
load_layout(corpus.slug, set_and_register=False)

11 changes: 11 additions & 0 deletions start/management/commands/runserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

from django.contrib.staticfiles.management.commands.runserver import Command as RunServerCommand
import explorer.parts.main

class Command(RunServerCommand):

def run(self, **options):
if os.environ.get('RUN_MAIN', False): # https://code.djangoproject.com/ticket/8085
explorer.parts.main.load_corpora()
super().run(**options)

0 comments on commit ae59990

Please sign in to comment.