Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion backend/kernelCI_app/queries/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ def get_issue_listing_data(
"start_date": start_date,
"end_date": end_date,
}
cache_params = {
"start_date": int(start_date.timestamp()),
"end_date": int(end_date.timestamp()),
}
cache_key = "issueList"

rows = get_query_cache(key=cache_key, params=cache_params)
if rows is not None:
return rows

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

with connection.cursor() as cursor:
cursor.execute(query, params)
return dict_fetchall(cursor)
rows = dict_fetchall(cursor)
set_query_cache(key=cache_key, params=cache_params, rows=rows)
return rows


# TODO: combine this query with the other queries for issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ def test_get_issue_tests_without_version(self, mock_connection, mock_dict_fetcha


class TestGetIssueListingData:
@patch("kernelCI_app.queries.issues.get_query_cache")
@patch("kernelCI_app.queries.issues.set_query_cache")
@patch("kernelCI_app.queries.issues.dict_fetchall")
@patch("kernelCI_app.queries.issues.connection")
def test_get_issue_listing_data_success(self, mock_connection, mock_dict_fetchall):
def test_get_issue_listing_data_success(
self, mock_connection, mock_dict_fetchall, mock_set_cache, mock_get_cache
):
mock_get_cache.return_value = None
expected_result = [{"id": "issue", "version": 1}]
mock_dict_fetchall.return_value = expected_result
setup_mock_cursor(mock_connection)
Expand All @@ -95,6 +100,7 @@ def test_get_issue_listing_data_success(self, mock_connection, mock_dict_fetchal
)

assert result == expected_result
mock_set_cache.assert_called_once()


class TestGetLatestIssueVersion:
Expand Down
Loading