Wrap symcache loading into `.from_scratch()`
Since we need it both when explicitly reloading **and** whenever either the file or data in the file doesn't exist.account_tests
parent
188508575a
commit
d0f72bf269
|
@ -274,6 +274,28 @@ class SymbologyCache(Struct):
|
||||||
)
|
)
|
||||||
return cache
|
return cache
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def from_scratch(
|
||||||
|
mod: ModuleType,
|
||||||
|
fp: Path,
|
||||||
|
**kwargs,
|
||||||
|
|
||||||
|
) -> SymbologyCache:
|
||||||
|
'''
|
||||||
|
Generate (a) new symcache (contents) entirely from scratch
|
||||||
|
including all (TOML) serialized data and file.
|
||||||
|
|
||||||
|
'''
|
||||||
|
log.info(f'GENERATING symbology cache for `{mod.name}`')
|
||||||
|
cache = SymbologyCache(
|
||||||
|
mod=mod,
|
||||||
|
fp=fp,
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
await cache.load()
|
||||||
|
cache.write_config()
|
||||||
|
return cache
|
||||||
|
|
||||||
def search(
|
def search(
|
||||||
self,
|
self,
|
||||||
pattern: str,
|
pattern: str,
|
||||||
|
@ -370,17 +392,11 @@ async def open_symcache(
|
||||||
reload
|
reload
|
||||||
or not cachefile.is_file()
|
or not cachefile.is_file()
|
||||||
):
|
):
|
||||||
cache = SymbologyCache(
|
cache = await SymbologyCache.from_scratch(
|
||||||
mod=mod,
|
mod=mod,
|
||||||
fp=cachefile,
|
fp=cachefile,
|
||||||
)
|
)
|
||||||
|
|
||||||
log.info(f'GENERATING symbology cache for `{mod.name}`')
|
|
||||||
await cache.load()
|
|
||||||
|
|
||||||
# NOTE: only (re-)write if explicit reload or non-existing
|
|
||||||
cache.write_config()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.info(
|
log.info(
|
||||||
f'Loading EXISTING `{mod.name}` symbology cache:\n'
|
f'Loading EXISTING `{mod.name}` symbology cache:\n'
|
||||||
|
@ -392,11 +408,20 @@ async def open_symcache(
|
||||||
data: dict[str, dict] = tomllib.load(existing_fp)
|
data: dict[str, dict] = tomllib.load(existing_fp)
|
||||||
log.runtime(f'SYMCACHE TOML LOAD TIME: {time.time() - now}')
|
log.runtime(f'SYMCACHE TOML LOAD TIME: {time.time() - now}')
|
||||||
|
|
||||||
cache = SymbologyCache.from_dict(
|
# if there's an empty file for some reason we need
|
||||||
data,
|
# to do a full reload as well!
|
||||||
mod=mod,
|
if not data:
|
||||||
fp=cachefile,
|
cache = await SymbologyCache.from_scratch(
|
||||||
)
|
mod=mod,
|
||||||
|
fp=cachefile,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
cache = SymbologyCache.from_dict(
|
||||||
|
data,
|
||||||
|
mod=mod,
|
||||||
|
fp=cachefile,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO: use a real profiling sys..
|
# TODO: use a real profiling sys..
|
||||||
# https://github.com/pikers/piker/issues/337
|
# https://github.com/pikers/piker/issues/337
|
||||||
|
|
Loading…
Reference in New Issue