2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-02-08 04:27:45 +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))
_hack_set = set()
def hack_save(survexblock):
# #### Horrible hack to be properly written as a cache
sb_list =[]
print_list = []
sb = survexblock
while sb.parent and sb != sb.parent:
sb_list.append((sb._blockid, sb))
if sb._blockid not in _hack_set:
sb_list.append((sb._blockid, sb))
print_list.append(sb)
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()
for sbo in sb_list:
id, sb = sbo
sb.save()
_hack_set.add(sb._blockid)
# #### Horrible hack to be properly written as a cache
class LoadingSurvex:
@@ -459,6 +464,7 @@ class LoadingSurvex:
adhocload = False
person_pending_cache = {} # indexed per survexblock UUID, so robust wrt PUSH/POP begin/end
_pending_block_saves = OrderedDict() # not {}, retain topological sort order
_pending_pr_saves = {} # a dict of lists indexed by survexblock UUID
def __init__(self):
@@ -591,7 +597,7 @@ class LoadingSurvex:
return final_chunks
# 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 = []
for blockid in self._pending_block_saves:
blocks.append(self._pending_block_saves[blockid])
@@ -615,8 +621,7 @@ class LoadingSurvex:
print(f"\n !! {len(topo_list)=} blocks. {len(blocks)=}", file=sys.stderr)
safe_chunks = get_generational_chunks_optimized(topo_list)
try:
for i, chunk in enumerate(safe_chunks):
print(f"Saving Chunk {i+1} ({len(chunk)} blocks)...", file=sys.stderr)
@@ -648,7 +653,6 @@ class LoadingSurvex:
except Exception as e:
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):
"""
Only used for a single person.
@@ -670,10 +674,10 @@ class LoadingSurvex:
parser="survex", message=message, url=None, sb=(survexblock.survexfile.path)
)
if survexblock._blockid not in self.trip_team_cache:
self.trip_team_cache[survexblock._blockid] = []
self.trip_team_cache[survexblock._blockid].append(personrole)
# print(f"-- trip_team_cache\n -- {survexblock=} - {survexblock._blockid}\n -- {trip_team_cache[survexblock._blockid]}\n -- {personrole}", file=sys.stderr)
if survexblock._blockid not in self._pending_pr_saves:
self._pending_pr_saves[survexblock._blockid] = []
self._pending_pr_saves[survexblock._blockid].append(personrole)
# print(f"-- _pending_pr_saves\n -- {survexblock=} - {survexblock._blockid}\n -- {_pending_pr_saves[survexblock._blockid]}\n -- {personrole}", file=sys.stderr)
return False
@@ -691,7 +695,7 @@ class LoadingSurvex:
return
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
# 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})"
print(self.insp + message)
# stash_data_issue(parser='survex', message=message, url=None, sb=survexblock)
survexblock.foreigners = True
else:
pe = GetPersonExpeditionNameLookup(expo).get(tm.lower())
if pe:
@@ -719,12 +724,12 @@ class LoadingSurvex:
"""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
"""
for blk in self.trip_team_cache:
# hack_save(survexblock)
print(f" - Saving {len(self._pending_pr_saves)} SurvexPersonRoles to db", file=sys.stderr)
for blk in self._pending_pr_saves:
# Now commit to db
pr_list = self.trip_team_cache[blk]
# print(f" PR_LIST {pr_list} {blk}", file=sys.stderr)
pr_list = self._pending_pr_saves[blk]
print(f" PR_LIST {pr_list} {blk}", file=sys.stderr)
valid_list = []
for pr in pr_list:
try:
@@ -741,7 +746,7 @@ class LoadingSurvex:
# print(f"+++ {pr.survexblock=} {pr.survexblock.id=} {pr.person=} {pr.personexpedition=}", file=sys.stderr)
# 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):
"""Collects team names. We might not have a date so cannot validate