Skip to content

Commit b096606

Browse files
committed
Cache _reverse_aliases in NodeMeta instead of recomputing on every call
1 parent 1b6a83c commit b096606

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

fairgraph/node.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from .utility import (
1818
as_list, # temporary for backwards compatibility (a lot of code imports it from here)
1919
expand_uri,
20-
invert_dict,
2120
normalize_data,
2221
types_match,
2322
)
@@ -224,7 +223,7 @@ def generate_query_properties(
224223
]
225224
else: # KGEmbedded
226225
query_properties = [QueryProperty("@type")]
227-
reverse_aliases = invert_dict(cls.aliases)
226+
reverse_aliases = cls._reverse_aliases
228227

229228
if with_reverse_properties:
230229
included_properties = cls.all_properties
@@ -407,7 +406,7 @@ def resolve(
407406
"""
408407
use_release_status = release_status or self.release_status or "released"
409408
if follow_links:
410-
reverse_aliases = invert_dict(self.__class__.aliases)
409+
reverse_aliases = self.__class__._reverse_aliases
411410
for prop in self.__class__.all_properties:
412411
if prop.is_link:
413412
follow_name = None

fairgraph/registry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from openminds.registry import Registry
1414

1515
from .base import OPENMINDS_VERSION
16+
from .utility import invert_dict
1617

1718
if TYPE_CHECKING:
1819
from .node import KGNode
@@ -48,6 +49,7 @@ def __new__(meta, name, bases, class_dict):
4849
class_dict["preferred_import_path"] = class_dict["class_name"]
4950
cls = Registry.__new__(meta, name, bases, class_dict)
5051
cls._property_lookup = {prop.name: prop for prop in (cls.properties + cls.reverse_properties)}
52+
cls._reverse_aliases = invert_dict(class_dict.get("aliases", {}))
5153
return cls
5254

5355
def _get_doc(cls) -> str:

0 commit comments

Comments
 (0)