Skip to content

Commit

Permalink
feat: cache of metric values for faster charts (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
cabreraalex authored Sep 13, 2023
1 parent 230b016 commit 4f5a28b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backend/zeno_backend/classes/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions backend/zeno_backend/processing/metrics/map.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -51,6 +53,7 @@ def count(
)


@lru_cache(maxsize=4096)
def metric_map(
metric: Metric | None,
project: str,
Expand Down

0 comments on commit 4f5a28b

Please sign in to comment.