mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-25 08:41:51 +00:00
make cache work even if timestamps wrong
This commit is contained in:
parent
a6e60c0bf7
commit
9e5bdace2c
@ -585,15 +585,19 @@ def LoadLogbookForExpedition(expedition):
|
||||
expect = entries[year]
|
||||
# print(" - Logbook for: " + year)
|
||||
|
||||
def validcache(year,n):
|
||||
def validcache(year,n, lbsize):
|
||||
if year != expedition:
|
||||
print(" ! year != expedition ",year, expedition )
|
||||
print(" ! cache loading: year != expedition ",year, expedition )
|
||||
return False
|
||||
currentsize = logbookpath.stat().st_size
|
||||
if lbsize != currentsize:
|
||||
print(f" ! cache loading: Logbook size {lbsize} != {currentsize} ")
|
||||
return False
|
||||
if len(logentries) != n:
|
||||
print(" ! len(logentries) != n ",len(logentries), n )
|
||||
print(" ! cache loading: len(logentries) != n ",len(logentries), n )
|
||||
return False
|
||||
if n != expect:
|
||||
print(" ! n != expect ",n, expect )
|
||||
print(" ! cache loading: n != expect ",n, expect )
|
||||
return False
|
||||
return True
|
||||
|
||||
@ -652,15 +656,15 @@ def LoadLogbookForExpedition(expedition):
|
||||
try:
|
||||
# print(" - Reading cache: " + str(cache_filename), end='')
|
||||
with open(cache_filename, "rb") as f:
|
||||
year,n,logentries = pickle.load(f)
|
||||
if validcache(year,n):
|
||||
year, lbsize, n, logentries = pickle.load(f)
|
||||
if validcache(year, n, lbsize):
|
||||
print(f" -- {year} : Loaded {len(logentries)} log entries")
|
||||
logbook_cached = True
|
||||
else:
|
||||
print(" !- Told to expect ", expect, " but ", len(logentries), " found in cache")
|
||||
print(" !- {year} : Cache failed validity checks")
|
||||
raise
|
||||
except:
|
||||
print(" ! Failed to load corrupt cache. (Or I was told to ignore it). Deleting it.")
|
||||
print(" ! Failed to load corrupt cache (or I was told to ignore it). Deleting it.")
|
||||
os.remove(cache_filename)
|
||||
logentries=[]
|
||||
raise
|
||||
@ -684,8 +688,9 @@ def LoadLogbookForExpedition(expedition):
|
||||
SetDatesFromLogbookEntries(expedition)
|
||||
if len(logentries) >0:
|
||||
print(" - Cacheing " , len(logentries), " log entries")
|
||||
lbsize = logbookpath.stat().st_size
|
||||
with open(cache_filename, "wb") as fc: # we much check that permission are g+w ! or expo can't delete the cache
|
||||
logbk=(expedition,len(logentries),logentries)
|
||||
logbk=(expedition,lbsize,len(logentries),logentries)
|
||||
pickle.dump(logbk, fc, protocol=4)
|
||||
else:
|
||||
print(" ! NO TRIP entries found in logbook, check the syntax.")
|
||||
@ -737,7 +742,7 @@ def LoadLogbooks():
|
||||
expd ={}
|
||||
actuals = []
|
||||
|
||||
for expo in expos:
|
||||
for expo in expos: # pointless as we explicitly know the years in this code.
|
||||
year = expo.year
|
||||
TROG['pagecache']['expedition'][year] = None # clear cache
|
||||
if year in sqlfail:
|
||||
|
Loading…
Reference in New Issue
Block a user