Skip to content

Commit

Permalink
Merge pull request #234 from intuitem/CA-358-Implement-memory-caching…
Browse files Browse the repository at this point in the history
…-for-deserialized-library-content

Implement memory caching for deserialized libary content
  • Loading branch information
eric-intuitem authored Apr 9, 2024
2 parents 5834003 + bd1eb27 commit 1927c90
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions backend/library/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get_available_library_files():
files.append(f)
return files

AVAILABLE_LIBRARIES = {}

def get_available_libraries():
"""
Expand All @@ -66,13 +67,18 @@ def get_available_libraries():
path = settings.BASE_DIR / "library/libraries"
libraries = []
for f in files:
with open(path / f, "r", encoding="utf-8") as file:
libs = yaml.safe_load_all(file)
for _lib in list(libs):
if (lib := Library.objects.filter(urn=_lib["urn"]).first()) is not None:
_lib["id"] = lib.id
_lib["reference_count"] = lib.reference_count
libraries.append(_lib)
fname = path / f
modified_time = os.path.getmtime(fname)
libs = AVAILABLE_LIBRARIES.get((fname,modified_time))
if libs is None :
with open(fname, "r", encoding="utf-8") as file:
libs = list(yaml.safe_load_all(file))
AVAILABLE_LIBRARIES[(fname,os.path.getmtime(fname))] = libs
for _lib in libs :
if (lib := Library.objects.filter(urn=_lib["urn"]).first()) is not None:
_lib["id"] = lib.id
_lib["reference_count"] = lib.reference_count
libraries.append(_lib)
return libraries


Expand Down

0 comments on commit 1927c90

Please sign in to comment.