Skip to content

Commit

Permalink
/* PR_START p--short-term-perf 06 */ Cache some properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Sep 24, 2024
1 parent 914a85d commit e258c30
Showing 1 changed file with 5 additions and 4 deletions.
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

0 comments on commit e258c30

Please sign in to comment.