2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-02-08 10:38:25 +00:00

cleaned horrible hack a bit and renames

This commit is contained in:
2026-01-29 23:53:15 +00:00
parent 5152802c6b
commit 89bc27b1f8

View File

@@ -221,20 +221,25 @@ def get_people_on_trip(survexblock):
return list(set(people)) return list(set(people))
_hack_set = set()
def hack_save(survexblock): def hack_save(survexblock):
# #### Horrible hack to be properly written as a cache # #### Horrible hack to be properly written as a cache
sb_list =[] sb_list =[]
print_list = []
sb = survexblock sb = survexblock
while sb.parent and sb != sb.parent: while sb.parent and sb != sb.parent:
if sb._blockid not in _hack_set:
sb_list.append((sb._blockid, sb)) sb_list.append((sb._blockid, sb))
print_list.append(sb)
sb = sb.parent sb = sb.parent
# print(sb_list, file=sys.stderr) if len(print_list) > 0:
print(f" ## Horrible QM pre-save hack: {len(print_list)} survexblocks up from {survexblock}", file=sys.stderr)
sb_list.reverse() sb_list.reverse()
for sbo in sb_list: for sbo in sb_list:
id, sb = sbo id, sb = sbo
sb.save() sb.save()
_hack_set.add(sb._blockid)
# #### Horrible hack to be properly written as a cache # #### Horrible hack to be properly written as a cache
class LoadingSurvex: class LoadingSurvex:
@@ -459,6 +464,7 @@ class LoadingSurvex:
adhocload = False adhocload = False
person_pending_cache = {} # indexed per survexblock UUID, so robust wrt PUSH/POP begin/end person_pending_cache = {} # indexed per survexblock UUID, so robust wrt PUSH/POP begin/end
_pending_block_saves = OrderedDict() # not {}, retain topological sort order _pending_block_saves = OrderedDict() # not {}, retain topological sort order
_pending_pr_saves = {} # a dict of lists indexed by survexblock UUID
def __init__(self): def __init__(self):
@@ -591,7 +597,7 @@ class LoadingSurvex:
return final_chunks return final_chunks
# construct the list. # construct the list.
already_saved_blocks = set(SurvexBlock.objects.values_list('_blockid', flat=True)) #already_saved_blocks = set(SurvexBlock.objects.values_list('_blockid', flat=True))
blocks = [] blocks = []
for blockid in self._pending_block_saves: for blockid in self._pending_block_saves:
blocks.append(self._pending_block_saves[blockid]) blocks.append(self._pending_block_saves[blockid])
@@ -616,7 +622,6 @@ class LoadingSurvex:
safe_chunks = get_generational_chunks_optimized(topo_list) safe_chunks = get_generational_chunks_optimized(topo_list)
try: try:
for i, chunk in enumerate(safe_chunks): for i, chunk in enumerate(safe_chunks):
print(f"Saving Chunk {i+1} ({len(chunk)} blocks)...", file=sys.stderr) print(f"Saving Chunk {i+1} ({len(chunk)} blocks)...", file=sys.stderr)
@@ -648,7 +653,6 @@ class LoadingSurvex:
except Exception as e: except Exception as e:
print(f" !! Error in bulk_create for survexblocks at {i}: {e}", file=sys.stderr) print(f" !! Error in bulk_create for survexblocks at {i}: {e}", file=sys.stderr)
trip_team_cache = {} # a dict of lists indexed by survexblock._blockid
def put_personrole_on_trip(self, survexblock, personexpedition, tm): def put_personrole_on_trip(self, survexblock, personexpedition, tm):
""" """
Only used for a single person. Only used for a single person.
@@ -670,10 +674,10 @@ class LoadingSurvex:
parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) parser="survex", message=message, url=None, sb=(survexblock.survexfile.path)
) )
if survexblock._blockid not in self.trip_team_cache: if survexblock._blockid not in self._pending_pr_saves:
self.trip_team_cache[survexblock._blockid] = [] self._pending_pr_saves[survexblock._blockid] = []
self.trip_team_cache[survexblock._blockid].append(personrole) self._pending_pr_saves[survexblock._blockid].append(personrole)
# print(f"-- trip_team_cache\n -- {survexblock=} - {survexblock._blockid}\n -- {trip_team_cache[survexblock._blockid]}\n -- {personrole}", file=sys.stderr) # print(f"-- _pending_pr_saves\n -- {survexblock=} - {survexblock._blockid}\n -- {_pending_pr_saves[survexblock._blockid]}\n -- {personrole}", file=sys.stderr)
return False return False
@@ -691,7 +695,7 @@ class LoadingSurvex:
return return
if not (expo := self.get_expo_for_block(survexblock)): if not (expo := self.get_expo_for_block(survexblock)):
print(f" Buggeration fAIL {survexblock=}",file=sys.stderr) print(f" Buggeration FAIL, undated but people exist {survexblock=}",file=sys.stderr)
return return
# Sanitise the set of names, and validate as valid people # Sanitise the set of names, and validate as valid people
@@ -701,6 +705,7 @@ class LoadingSurvex:
message = f"- *team '{tm}' known foreigner {survexblock.survexfile.path} ({survexblock})" message = f"- *team '{tm}' known foreigner {survexblock.survexfile.path} ({survexblock})"
print(self.insp + message) print(self.insp + message)
# stash_data_issue(parser='survex', message=message, url=None, sb=survexblock) # stash_data_issue(parser='survex', message=message, url=None, sb=survexblock)
survexblock.foreigners = True
else: else:
pe = GetPersonExpeditionNameLookup(expo).get(tm.lower()) pe = GetPersonExpeditionNameLookup(expo).get(tm.lower())
if pe: if pe:
@@ -719,12 +724,12 @@ class LoadingSurvex:
"""This should be run only after all the survexblocks have """This should be run only after all the survexblocks have
been saved to the database and so have _id that can be used as a ForeignKey been saved to the database and so have _id that can be used as a ForeignKey
""" """
for blk in self.trip_team_cache: print(f" - Saving {len(self._pending_pr_saves)} SurvexPersonRoles to db", file=sys.stderr)
# hack_save(survexblock) for blk in self._pending_pr_saves:
# Now commit to db # Now commit to db
pr_list = self.trip_team_cache[blk] pr_list = self._pending_pr_saves[blk]
# print(f" PR_LIST {pr_list} {blk}", file=sys.stderr) print(f" PR_LIST {pr_list} {blk}", file=sys.stderr)
valid_list = [] valid_list = []
for pr in pr_list: for pr in pr_list:
try: try:
@@ -741,7 +746,7 @@ class LoadingSurvex:
# print(f"+++ {pr.survexblock=} {pr.survexblock.id=} {pr.person=} {pr.personexpedition=}", file=sys.stderr) # print(f"+++ {pr.survexblock=} {pr.survexblock.id=} {pr.person=} {pr.personexpedition=}", file=sys.stderr)
# SurvexPersonRole.objects.create(pr).save() # SurvexPersonRole.objects.create(pr).save()
trip_team_cache = {} # in database now, so empty cache _pending_pr_saves = {} # in database now, so empty cache
def add_to_pending(self, survexblock, tm): def add_to_pending(self, survexblock, tm):
"""Collects team names. We might not have a date so cannot validate """Collects team names. We might not have a date so cannot validate