Project

General

Profile

Design Notes

AJAX content loading caching system

The content for the reading pages is cached in order to reduce the loading time of the chapters. This is necessary because rendering is expensive. This works by:

  1. Caching the current page on the server
  2. Pre-loading the next page so that it is pre-cached

The way that this works is that the template for the page will only return the non-content part of the page if the request is not an AJAX request. This will not be cached.

On the other hand. if the request is for an AJAX request, then only the content part of the page will be returned. This will be cached.

ajaxify: what does it do?

The ajaxify decorator changes the page that will be returned such that it is a shell that will request the actual page. This is useful in order to show content to a user quickly with a progress-bar instead of showing a white screen while the content is prepared.

How the type-ahead system in the search works

  1. The search-query uses the Bootstrap type-ahead component to invoke a call to get_works_search_typeahead_hints()
  2. get_works_search_typeahead_hints() obtains the type-ahead hints for Bootstrap
  3. On submitting the search query, jump_to_searched_text() will be used to jump directly to the matching work

How are related works identified in the importer?

The RelatedWork model function autodiscover() attempts to find related works and link them. It considers them comparable when:
  1. The number of authors are the same and the authors names are the same and in the same order
  2. The number of editors are the same and the editors names are the same and in the same order
  3. The divisions are the same (same number of them and the descriptors are the same and in the same order)

How search indexes get re-populated

There is a built-in command to re-index works. For example:

python manage.py make_search_indexes -w lxx

If you want to clear the existing index for a work before indexing it, then include the -f option:

python manage.py make_search_indexes -f -w lxx

You can clear the index entirely with:

python manage.py make_search_indexes -c

You can re-create the index entirely with:

python manage.py make_search_indexes

How to populate related works

The following will be compared to see if two works are equivalent:

  1. TItles
  2. Count of authors
  3. Author names
  4. Count of editors (optionally)
  5. Editor names (optionally)
  6. Divisions (optionally)

This can be done in code with the following:

from reader.models import RelatedWork
RelatedWork.autodiscover()

You can also use the autodiscover_related_works command to link related works. Generally, I suggest starting with the test parameter to see what would be linked:

python manage.py autodiscover_related_works -w the-histories-greek --test

If you want the linkage to be created, then run the command without the test parameter:

python manage.py autodiscover_related_works -w the-histories-greek

How can I import Perseus works?

You can batch import Perseus works by running the batch_import_perseus command against a directory of Perseus works:

python manage.py batch_import_perseus -d var/import_queue/

The command above will import the work according to the import policy (thus using the recommended settings).

What is the purpose of the Perseus import policy?

The import policy indicates if a work will be imported and what settings will be used. Here is how the importer uses the policy:

  1. Gets import policy. Stop is there is no matching import policy.
  2. The PerseusTextImporter is called with the import policy
  3. The is imported unless the file doesn't already exist or is directed to force update

Similar works are linked using the autodiscover() function in the RelatedWork class. This needs to be called manually since the import process doesn't do this automatically.

How does the AJAH system work?

The intention of this system is to quickly load a loading page and then get the main content a bit later.

  • ajaxify: renders a page which in turns will get the content asynchronously
  • ajah_redirect.html: a template that loads the HTML holder page and calls TextCritical.load_ajah() to get the main content.
  • TextCritical.load_ajah(): The main content will be retrieved with the argument necessary to only get the main content, not the surrounding page.

How are division reference lookups done?

This is done in reader.views. It goes like this:

  • read_work: attempts to find the division, will complain if a division cannot be found that is an exact match
  • get_division_and_verse: Will return the parent divisions followed by the division that contains the verse
  • get_division: Will find a division that matches the given list of strings by doing database queries