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

Change cache in MetricTimeQueryValidationRule to LruCache #1457

Merged
merged 1 commit into from
Oct 16, 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
@@ -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
Loading