diff --git a/backend/zeno_backend/classes/metric.py b/backend/zeno_backend/classes/metric.py index d5727d3d..308cd142 100644 --- a/backend/zeno_backend/classes/metric.py +++ b/backend/zeno_backend/classes/metric.py @@ -18,6 +18,14 @@ class Metric(CamelModel): type: str columns: list[str] + def __hash__(self): + """Hash representation of metric, based on id since guaranteed unique. + + Returns: + int: the hash of the metric. + """ + return self.id + class MetricKey(CamelModel): """Specification of metric keys in zeno. diff --git a/backend/zeno_backend/processing/metrics/map.py b/backend/zeno_backend/processing/metrics/map.py index dae43e58..657ae7bd 100644 --- a/backend/zeno_backend/processing/metrics/map.py +++ b/backend/zeno_backend/processing/metrics/map.py @@ -1,5 +1,7 @@ """Map metric names to metric functions.""" +from functools import lru_cache + from psycopg import sql from zeno_backend.classes.base import GroupMetric @@ -51,6 +53,7 @@ def count( ) +@lru_cache(maxsize=4096) def metric_map( metric: Metric | None, project: str,