diff --git a/parsers/logbooks.py b/parsers/logbooks.py index d693b9a..8fc78d6 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -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: