From bb14c94ab10cbd279586c97822372bba8375b67b Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 19 Dec 2022 20:13:26 +0000 Subject: Updates to make 2018 blog merge work (faster) --- core/views/logbooks.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'core/views/logbooks.py') diff --git a/core/views/logbooks.py b/core/views/logbooks.py index 517a48b..52e2d11 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -1,4 +1,5 @@ import datetime +import time import os.path import re @@ -186,24 +187,26 @@ def personexpedition(request, first_name='', last_name='', year=''): def logbookentry(request, date, slug): - this_logbookentry = LogbookEntry.objects.filter(date=date, slug=slug) + # start = time.time() + trips = LogbookEntry.objects.filter(date=date) # all the trips not just this one + this_logbookentry = trips.filter(date=date, slug=slug) if this_logbookentry: if len(this_logbookentry)>1: return render(request, 'object_list.html',{'object_list':this_logbookentry}) else: - trips = LogbookEntry.objects.filter(date=date) wallets = set() - refwallets = Wallet.objects.filter(survexblock__date=date) + allwallets = Wallet.objects.all() + refwallets = allwallets.filter(survexblock__date=date) for r in refwallets: wallets.add(r) - - allwallets = Wallet.objects.all() + # Note that w.year() only works for wallets which have a valid JSON file existing - for w in allwallets: - if w.date() == date: - wallets.add(w) - + # This is very slow with a big lag as w.date() is a computed field + # Noticably slow with WSL2 and NTFS filesystem, even with caching as walletdate. + jwallets = allwallets.filter(walletdate=date) + for j in jwallets: + wallets.add(j) thisexpo = this_expedition = Expedition.objects.get(year=int(date[0:4])) if thisexpo: expeditionday = thisexpo.get_expedition_day(date) @@ -214,6 +217,8 @@ def logbookentry(request, date, slug): this_logbookentry=this_logbookentry[0] # This is the only page that uses presontrip_next and persontrip_prev # and it is calculated on the fly in the model + # duration = time.time()-start + # print(f"--- Render after {duration:.2f} seconds") return render(request, 'logbookentry.html', {'logbookentry': this_logbookentry, 'trips': trips, 'svxothers': svxothers, 'wallets': wallets}) else: -- cgit v1.2.3