diff --git a/CHANGELOG.md b/CHANGELOG.md index 8eeed54fc829649a58a14cf60fbf85a48b0ae48a..13be62dbc87482656b3325334a158711e2c73651 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - If a registered identifiable states, that a reference by a Record with parent RT1 is needed, then now also references from Records that have a child of RT1 as parent are accepted. +- More aggressive caching. ### Deprecated ### diff --git a/src/caoscrawler/identifiable_adapters.py b/src/caoscrawler/identifiable_adapters.py index ceaa3bfe1f1f040fc0099d17e14a0c6797804ac4..64b9d380111ce7f1886ba5c77d4d9ce140ae9e3d 100644 --- a/src/caoscrawler/identifiable_adapters.py +++ b/src/caoscrawler/identifiable_adapters.py @@ -27,12 +27,13 @@ from __future__ import annotations import logging from abc import ABCMeta, abstractmethod +from functools import lru_cache from datetime import datetime from typing import Any import caosdb as db import yaml -from caosdb.cached import cached_get_entity_by +from caosdb.cached import cached_get_entity_by, cached_query from .identifiable import Identifiable from .utils import has_parent @@ -43,7 +44,7 @@ logger = logging.getLogger(__name__) def get_children_of_rt(rtname): """Supply the name of a recordtype. This name and the name of all children RTs are returned in a list""" - return [p.name for p in db.execute_query(f"FIND RECORDTYPE {rtname}")] + return [p.name for p in cached_query(f"FIND RECORDTYPE {rtname}")] def convert_value(value: Any): @@ -510,7 +511,7 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter): def retrieve_identified_record_for_identifiable(self, identifiable: Identifiable): query_string = self.create_query_for_identifiable(identifiable) - candidates = db.execute_query(query_string) + candidates = cached_query(query_string) if len(candidates) > 1: raise RuntimeError( f"Identifiable was not defined unambigiously.\n{query_string}\nReturned the "