Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache some properties immutable properties #1423

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
from collections import defaultdict
from dataclasses import dataclass, field
from functools import cached_property
from typing import Dict, FrozenSet, List, Sequence, Set, Tuple

from dbt_semantic_interfaces.enum_extension import assert_values_exhausted
Expand Down Expand Up @@ -282,7 +283,7 @@ def filter(
path_key_to_linkable_metrics=key_to_linkable_metrics,
)

@property
@cached_property
def only_unique_path_keys(self) -> LinkableElementSet:
"""Returns a set that only includes path keys that map to a single distinct element."""
return LinkableElementSet(
Expand All @@ -303,7 +304,7 @@ def only_unique_path_keys(self) -> LinkableElementSet:
},
)

@property
@cached_property
@override
def derived_from_semantic_models(self) -> Sequence[SemanticModelReference]:
semantic_model_references: Set[SemanticModelReference] = set()
Expand All @@ -319,7 +320,7 @@ def derived_from_semantic_models(self) -> Sequence[SemanticModelReference]:

return sorted(semantic_model_references, key=lambda reference: reference.semantic_model_name)

@property
@cached_property
def spec_count(self) -> int:
"""If this is mapped to spec objects, the number of specs that would be produced."""
return (
Expand All @@ -328,7 +329,7 @@ def spec_count(self) -> int:
+ len(self.path_key_to_linkable_metrics.keys())
)

@property
@cached_property
def specs(self) -> Sequence[LinkableInstanceSpec]:
"""Converts the items in a `LinkableElementSet` to their corresponding spec objects."""
specs: List[LinkableInstanceSpec] = []
Expand Down
Loading