summaryrefslogtreecommitdiffstats
path: root/core/views/logbooks.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2025-01-10 00:28:01 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2025-01-10 00:28:01 +0000
commit49c0c0fe3ad054704329ad5204446056487e2424 (patch)
treecfae504f740e4cc02996189a5efaeadaa5e1f9e0 /core/views/logbooks.py
parent486a50f876354a8447886a33042f0f7517316078 (diff)
downloadtroggle-49c0c0fe3ad054704329ad5204446056487e2424.tar.gz
troggle-49c0c0fe3ad054704329ad5204446056487e2424.tar.bz2
troggle-49c0c0fe3ad054704329ad5204446056487e2424.zip
First attempts at better use of Django query optimisation
Diffstat (limited to 'core/views/logbooks.py')
-rw-r--r--core/views/logbooks.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/core/views/logbooks.py b/core/views/logbooks.py
index 003b67f..8b62368 100644
--- a/core/views/logbooks.py
+++ b/core/views/logbooks.py
@@ -16,7 +16,7 @@ from troggle.parsers.imports import import_logbook
"""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.
+It uses the global object TROG to hold some cached pages. USELESS as cache only works single-threaded, single-user.
"""
todo = """- Fix the get_person_chronology() display bug.
@@ -91,17 +91,16 @@ def expedition(request, expeditionname):
# print('! - expo {expeditionanme} using cached page')
return render(request, "expedition.html", {**ts[expeditionname], "logged_in": logged_in})
- expeditions = Expedition.objects.all() # top menu only, evaluated only when template renders
- entries = expo.logbookentry_set.all()
- blocks = expo.survexblock_set.all()
+ entries = expo.logbookentry_set.only('date','title').filter(expedition=expo)
+ blocks = expo.survexblock_set.only('date','name').filter(expedition=expo).prefetch_related('scanswallet', 'survexfile')
dateditems = list(entries) + list(blocks) # evaluates the Django query and hits db
dates = sorted(set([item.date for item in dateditems]))
- allpersonlogentries = PersonLogEntry.objects.filter(personexpedition__expedition=expo)
+ allpersonlogentries = PersonLogEntry.objects.prefetch_related('logbook_entry').select_related('personexpedition__expedition').filter(personexpedition__expedition=expo)
personexpodays = []
- for personexpedition in expo.personexpedition_set.all():
+ for personexpedition in expo.personexpedition_set.all().prefetch_related('person'):
expotrips = allpersonlogentries.filter(personexpedition=personexpedition) # lazy
expoblocks = blocks.filter(survexpersonrole__personexpedition=personexpedition)
@@ -118,6 +117,8 @@ def expedition(request, expeditionname):
prow.append(pcell)
personexpodays.append({"personexpedition": personexpedition, "personrow": prow, "sortname": personexpedition.person.last_name})
+ expeditions = Expedition.objects.only('year') # top menu only, evaluated only when template renders, only need "year"
+
ts[expeditionname] = {
"year": int(expeditionname),
"expedition": expo,