Skip to content

Commit

Permalink
Change cache in MetricTimeQueryValidationRule to LruCache.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Oct 15, 2024
1 parent 15a6ae7 commit b10f09e
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from __future__ import annotations

from dataclasses import dataclass
from functools import lru_cache
from typing import List, Sequence
from typing import List, Sequence, Tuple

from dbt_semantic_interfaces.enum_extension import assert_values_exhausted
from dbt_semantic_interfaces.naming.keywords import METRIC_TIME_ELEMENT_NAME
Expand All @@ -14,6 +13,7 @@
from dbt_semantic_interfaces.type_enums import MetricType
from typing_extensions import override

from metricflow_semantics.collection_helpers.lru_cache import LruCache
from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup
from metricflow_semantics.query.group_by_item.resolution_path import MetricFlowQueryResolutionPath
from metricflow_semantics.query.issues.issues_base import MetricFlowQueryResolutionIssueSet
Expand Down Expand Up @@ -65,10 +65,23 @@ def __init__( # noqa: D107
custom_granularities=self._manifest_lookup.custom_granularities,
)
)
self._query_items_analysis_cache: LruCache[
Tuple[ResolverInputForQuery, MetricReference], QueryItemsAnalysis
] = LruCache(128)

@lru_cache
def _get_query_items_analysis(
self, query_resolver_input: ResolverInputForQuery, metric_reference: MetricReference
) -> QueryItemsAnalysis:
cache_key = (query_resolver_input, metric_reference)
result = self._query_items_analysis_cache.get(cache_key)
if result is not None:
return result
result = self._uncached_query_items_analysis(query_resolver_input, metric_reference)
self._query_items_analysis_cache.set(cache_key, result)
return result

def _uncached_query_items_analysis(
self, query_resolver_input: ResolverInputForQuery, metric_reference: MetricReference
) -> QueryItemsAnalysis:
has_agg_time_dimension = False
has_metric_time = False
Expand Down

0 comments on commit b10f09e

Please sign in to comment.