Skip to content

Commit a5e93fc

Browse files
author
Gustavo Flores
authored
feat: increase metrics cache time (#1934)
1 parent dbf1a54 commit a5e93fc

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

backend/kernelCI_app/queries/notifications.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
TopIssue,
1717
)
1818

19+
METRICS_CACHE_TIMEOUT = 60 * 60 * 6 # 6 hours
20+
1921

2022
def kcidb_execute_query(query, params=None):
2123
try:
@@ -645,7 +647,13 @@ def get_issues_summary_data(*, checkout_ids: list[str]) -> list[dict]:
645647
return dict_fetchall(cursor=cursor)
646648

647649

648-
def query_fetchone_work(*, cache_key: str, query: str, params: dict[str, Any]):
650+
def query_fetchone_work(
651+
*,
652+
cache_key: str,
653+
query: str,
654+
params: dict[str, Any],
655+
timeout: int = METRICS_CACHE_TIMEOUT,
656+
):
649657
rows = get_query_cache(key=cache_key, params=params)
650658
if rows is not None:
651659
return rows
@@ -655,11 +663,17 @@ def query_fetchone_work(*, cache_key: str, query: str, params: dict[str, Any]):
655663
rows = cursor.fetchone()
656664
finally:
657665
connections["default"].close()
658-
set_query_cache(key=cache_key, params=params, rows=rows)
666+
set_query_cache(key=cache_key, params=params, rows=rows, timeout=timeout)
659667
return rows
660668

661669

662-
def query_fetchall_work(*, cache_key: str, query: str, params: dict[str, Any]):
670+
def query_fetchall_work(
671+
*,
672+
cache_key: str,
673+
query: str,
674+
params: dict[str, Any],
675+
timeout: int = METRICS_CACHE_TIMEOUT,
676+
):
663677
rows = get_query_cache(key=cache_key, params=params)
664678
if rows is not None:
665679
return rows
@@ -669,7 +683,7 @@ def query_fetchall_work(*, cache_key: str, query: str, params: dict[str, Any]):
669683
rows = cursor.fetchall()
670684
finally:
671685
connections["default"].close()
672-
set_query_cache(key=cache_key, params=params, rows=rows)
686+
set_query_cache(key=cache_key, params=params, rows=rows, timeout=timeout)
673687
return rows
674688

675689

backend/kernelCI_app/urls.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
)
99

1010
from kernelCI_app import views
11+
from kernelCI_app.queries.notifications import METRICS_CACHE_TIMEOUT
1112

1213

1314
def view_cache(view, timeout: int = settings.CACHE_TIMEOUT):
@@ -179,5 +180,9 @@ def view_cache(view, timeout: int = settings.CACHE_TIMEOUT):
179180
path("proxy/", views.ProxyView.as_view(), name="proxyView"),
180181
path("origins/", views.OriginsView.as_view(), name="originsView"),
181182
path("tree-report/", views.TreeReport.as_view(), name="treeReportView"),
182-
path("metrics/", view_cache(views.MetricsView), name="metricsView"),
183+
path(
184+
"metrics/",
185+
view_cache(views.MetricsView, timeout=METRICS_CACHE_TIMEOUT),
186+
name="metricsView",
187+
),
183188
]

0 commit comments

Comments
 (0)