Skip to content

Commit 0e6d202

Browse files
committed
feat: add cache to issue listing query
Closes #1615 Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi>
1 parent b9f9d1e commit 0e6d202

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

backend/kernelCI_app/queries/issues.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ def get_issue_listing_data(
111111
"start_date": start_date,
112112
"end_date": end_date,
113113
}
114+
cache_params = {
115+
"start_date": int(start_date.timestamp()),
116+
"end_date": int(end_date.timestamp()),
117+
}
118+
cache_key = "issueList"
119+
120+
rows = get_query_cache(key=cache_key, params=cache_params)
121+
if rows is not None:
122+
return rows
114123

115124
# Note that an issue with timestamp younger than x days ago
116125
# can still have incidents in tests older than x days ago
@@ -139,7 +148,9 @@ def get_issue_listing_data(
139148

140149
with connection.cursor() as cursor:
141150
cursor.execute(query, params)
142-
return dict_fetchall(cursor)
151+
rows = dict_fetchall(cursor)
152+
set_query_cache(key=cache_key, params=cache_params, rows=rows)
153+
return rows
143154

144155

145156
# TODO: combine this query with the other queries for issues

backend/kernelCI_app/tests/unitTests/queries/issues_queries_test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,14 @@ def test_get_issue_tests_without_version(self, mock_connection, mock_dict_fetcha
8282

8383

8484
class TestGetIssueListingData:
85+
@patch("kernelCI_app.queries.issues.get_query_cache")
86+
@patch("kernelCI_app.queries.issues.set_query_cache")
8587
@patch("kernelCI_app.queries.issues.dict_fetchall")
8688
@patch("kernelCI_app.queries.issues.connection")
87-
def test_get_issue_listing_data_success(self, mock_connection, mock_dict_fetchall):
89+
def test_get_issue_listing_data_success(
90+
self, mock_connection, mock_dict_fetchall, mock_set_cache, mock_get_cache
91+
):
92+
mock_get_cache.return_value = None
8893
expected_result = [{"id": "issue", "version": 1}]
8994
mock_dict_fetchall.return_value = expected_result
9095
setup_mock_cursor(mock_connection)
@@ -95,6 +100,7 @@ def test_get_issue_listing_data_success(self, mock_connection, mock_dict_fetchal
95100
)
96101

97102
assert result == expected_result
103+
mock_set_cache.assert_called_once()
98104

99105

100106
class TestGetLatestIssueVersion:

0 commit comments

Comments
 (0)