mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-02-08 10:38:25 +00:00
cache expeditions - trivial
This commit is contained in:
@@ -843,26 +843,16 @@ class LoadingSurvex:
|
|||||||
|
|
||||||
def get_expo_from_year(self, year, line, survexblock):
|
def get_expo_from_year(self, year, line, survexblock):
|
||||||
# cacheing to save DB query on every block
|
# cacheing to save DB query on every block
|
||||||
if year in self.expos:
|
# Minimize ORM calls: cache all expeditions by year on first use
|
||||||
expo = self.expos[year]
|
if not hasattr(self, '_expedition_cache'):
|
||||||
|
self._expedition_cache = {e.year: e for e in Expedition.objects.all()}
|
||||||
|
if year in self._expedition_cache:
|
||||||
|
expo = self._expedition_cache[year]
|
||||||
else:
|
else:
|
||||||
expeditions = Expedition.objects.filter(year=year)
|
message = f"! DATE INCORRECT. There is no expedition for the year {year}. {survexblock.survexfile.path} ({survexblock}) - set to 1976."
|
||||||
if len(expeditions) > 1:
|
print(self.insp + message)
|
||||||
message = (
|
stash_data_issue(parser='survex', message=message, url=None, sb=(survexblock.survexfile.path))
|
||||||
f"! More than one expedition in year {year} '{line}' ({survexblock}) {survexblock.survexfile.path}"
|
expo = self._expedition_cache.get("1976")
|
||||||
)
|
|
||||||
print(self.insp + message)
|
|
||||||
stash_data_issue(
|
|
||||||
parser="survex", message=message, url=None, sb=(survexblock.survexfile.path)
|
|
||||||
)
|
|
||||||
if expeditions:
|
|
||||||
expo = expeditions[0]
|
|
||||||
self.expos[year] = expo
|
|
||||||
else:
|
|
||||||
expo = Expedition.objects.get(year="1976")
|
|
||||||
message = f"! DATE INCORRECT. There is no expedition for the year {year}. {survexblock.survexfile.path} ({survexblock}) - set to 1976."
|
|
||||||
print(self.insp + message)
|
|
||||||
stash_data_issue(parser='survex', message=message, url=None, sb=(survexblock.survexfile.path))
|
|
||||||
return expo
|
return expo
|
||||||
|
|
||||||
def LoadSurvexDate(self, survexblock, line):
|
def LoadSurvexDate(self, survexblock, line):
|
||||||
|
|||||||
Reference in New Issue
Block a user