mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-03-21 09:41:57 +00:00
Cache enabled for 'expedition' pages
This commit is contained in:
parent
16a6e05849
commit
6dc54adec8
@ -32,7 +32,11 @@ There are more subclasses define in models_caves.py models_survex.py etc.
|
|||||||
# This variable is a dictionary holding gloablly visible indexes and cache functions.
|
# This variable is a dictionary holding gloablly visible indexes and cache functions.
|
||||||
# It is a Global Object, see https://python-patterns.guide/python/module-globals/
|
# It is a Global Object, see https://python-patterns.guide/python/module-globals/
|
||||||
# troggle.models.TROG
|
# troggle.models.TROG
|
||||||
TROG = {}
|
TROG = {
|
||||||
|
'pagecache' : {
|
||||||
|
'expedition' : {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def get_process_memory():
|
def get_process_memory():
|
||||||
usage=resource.getrusage(resource.RUSAGE_SELF)
|
usage=resource.getrusage(resource.RUSAGE_SELF)
|
||||||
|
@ -12,10 +12,9 @@ from django.template.defaultfilters import slugify
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.views.generic.list import ListView
|
from django.views.generic.list import ListView
|
||||||
|
|
||||||
import troggle.core.models as models
|
#import troggle.parsers.logbooks as logbookparsers
|
||||||
import troggle.parsers.logbooks as logbookparsers
|
|
||||||
from troggle.core.forms import getTripForm # , get_name, PersonForm
|
from troggle.core.forms import getTripForm # , get_name, PersonForm
|
||||||
from troggle.core.models import Expedition, Person, PersonExpedition
|
from troggle.core.models import Expedition, Person, PersonExpedition, TROG
|
||||||
from troggle.core.models_caves import LogbookEntry, PersonTrip
|
from troggle.core.models_caves import LogbookEntry, PersonTrip
|
||||||
from troggle.core.models_survex import SurvexBlock
|
from troggle.core.models_survex import SurvexBlock
|
||||||
from .login import login_required_if_public
|
from .login import login_required_if_public
|
||||||
@ -24,6 +23,11 @@ from troggle.parsers.people import GetPersonExpeditionNameLookup
|
|||||||
|
|
||||||
import troggle.settings as settings
|
import troggle.settings as settings
|
||||||
|
|
||||||
|
'''These views are for logbook items when they appear in an 'expedition' page
|
||||||
|
and for persons: their individual pages and their perseonexpedition pages.
|
||||||
|
|
||||||
|
It uses the global object TROG to hold some cached pages.
|
||||||
|
'''
|
||||||
|
|
||||||
def getNotablePersons():
|
def getNotablePersons():
|
||||||
notablepersons = []
|
notablepersons = []
|
||||||
@ -51,7 +55,27 @@ def personindex(request):
|
|||||||
|
|
||||||
|
|
||||||
def expedition(request, expeditionname):
|
def expedition(request, expeditionname):
|
||||||
|
'''Returns a rendered page for one expedition, specified by the year e.g. '2019'.
|
||||||
|
If page caching is enabled, it caches the dictionaries used to render the template page.
|
||||||
|
|
||||||
|
The cache is refreshed if '?reload' is present in the requesting URL, which also re-parses the logbook.
|
||||||
|
By specifying a '0' for the expected number of entries in the logbook cache, this forces the parser to
|
||||||
|
re-parse the original logbook HTML file.
|
||||||
|
'''
|
||||||
|
if "reload" in request.GET:
|
||||||
|
this_expedition = Expedition.objects.get(year=int(expeditionname))
|
||||||
|
LoadLogbookForExpedition(this_expedition, 0)
|
||||||
|
|
||||||
|
ts = TROG['pagecache']['expedition']
|
||||||
|
if settings.CACHEDPAGES:
|
||||||
|
nexpos = len( TROG['pagecache']['expedition'])
|
||||||
|
#print(f'! - expo {expeditionname} CACHEDPAGES {nexpos} expo pages in cache.')
|
||||||
|
if expeditionname in ts:
|
||||||
|
#print('! - expo {expeditionanme} using cached page')
|
||||||
|
return render(request,'expedition.html', ts[expeditionname] )
|
||||||
|
|
||||||
this_expedition = Expedition.objects.get(year=int(expeditionname))
|
this_expedition = Expedition.objects.get(year=int(expeditionname))
|
||||||
|
|
||||||
expeditions = Expedition.objects.all()
|
expeditions = Expedition.objects.all()
|
||||||
personexpeditiondays = [ ]
|
personexpeditiondays = [ ]
|
||||||
dateditems = list(this_expedition.logbookentry_set.all()) + list(this_expedition.survexblock_set.all())
|
dateditems = list(this_expedition.logbookentry_set.all()) + list(this_expedition.survexblock_set.all())
|
||||||
@ -66,9 +90,14 @@ def expedition(request, expeditionname):
|
|||||||
prow.append(pcell)
|
prow.append(pcell)
|
||||||
personexpeditiondays.append({"personexpedition":personexpedition, "personrow":prow})
|
personexpeditiondays.append({"personexpedition":personexpedition, "personrow":prow})
|
||||||
|
|
||||||
if "reload" in request.GET:
|
|
||||||
LoadLogbookForExpedition(this_expedition)
|
ts[expeditionname] = {'expedition': this_expedition, 'expeditions':expeditions,
|
||||||
return render(request,'expedition.html', {'expedition': this_expedition, 'expeditions':expeditions, 'personexpeditiondays':personexpeditiondays, 'settings':settings, 'dateditems': dateditems })
|
'personexpeditiondays':personexpeditiondays, 'settings':settings,
|
||||||
|
'dateditems': dateditems }
|
||||||
|
TROG['pagecache']['expedition'][expeditionname] = ts[expeditionname]
|
||||||
|
nexpos = len( TROG['pagecache']['expedition'])
|
||||||
|
#print(f'! - expo {expeditionname} pre-render N expos:{nexpos}')
|
||||||
|
return render(request,'expedition.html', ts[expeditionname] )
|
||||||
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user