Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 86ce2fb

Browse files
Adjust call used in comparison file to avoid provider api call (#1176)
1 parent f4f7dc8 commit 86ce2fb

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

graphql_api/types/comparison/comparison.py

-4
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,6 @@ def resolve_has_different_number_of_head_and_base_reports(
252252
if "comparison" not in info.context:
253253
return False
254254
comparison: Comparison = info.context["comparison"]
255-
try:
256-
comparison.validate()
257-
except Exception:
258-
return False
259255
return comparison.has_different_number_of_head_and_base_sessions
260256

261257

services/comparison.py

+33-9
Original file line numberDiff line numberDiff line change
@@ -728,14 +728,41 @@ def head_report(self):
728728
pass
729729
return report
730730

731+
@cached_property
732+
def head_report_without_applied_diff(self):
733+
"""
734+
This is a variant to the head_report property without having an applied diff.
735+
This is created because applying the diff calls the provider, which adds a
736+
diff_totals key to the head_report object as well as adjusting the diff_total
737+
values in each session. This variant should only be used if you are not using
738+
any diff related data, as it saves an unnecessary request to the provider otherwise.
739+
"""
740+
try:
741+
report = report_service.build_report_from_commit(self.head_commit)
742+
except minio.error.S3Error as e:
743+
if e.code == "NoSuchKey":
744+
raise MissingComparisonReport("Missing head report")
745+
else:
746+
raise e
747+
748+
return report
749+
731750
@cached_property
732751
def has_different_number_of_head_and_base_sessions(self):
733-
log.info("has_different_number_of_head_and_base_sessions - Start")
734-
head_sessions = self.head_report.sessions
735-
base_sessions = self.base_report.sessions
736-
log.info(
737-
f"has_different_number_of_head_and_base_sessions - Retrieved sessions - head {len(head_sessions)} / base {len(base_sessions)}"
738-
)
752+
"""
753+
This method checks if the head and the base have different number of sessions.
754+
It makes use of the head_report_without_applied_diff property instead of the
755+
head_report one as it doesn't need diff related data for this computation (see
756+
the description of that property above for more context).
757+
This method should be replaced with a direct call to the report_uploads table instead,
758+
but leaving the implementation the same for now for consistency.
759+
"""
760+
try:
761+
head_sessions = self.head_report_without_applied_diff.sessions
762+
base_sessions = self.base_report.sessions
763+
except Exception:
764+
return False
765+
739766
# We're treating this case as false since considering CFF's complicates the logic
740767
if self._has_cff_sessions(head_sessions) or self._has_cff_sessions(
741768
base_sessions
@@ -746,12 +773,9 @@ def has_different_number_of_head_and_base_sessions(self):
746773
# I feel this method should belong to the API Report class, but we're thinking of getting rid of that class soon
747774
# In truth, this should be in the shared.Report class
748775
def _has_cff_sessions(self, sessions) -> bool:
749-
log.info(f"_has_cff_sessions - sessions count {len(sessions)}")
750776
for session in sessions.values():
751777
if session.session_type.value == "carriedforward":
752-
log.info("_has_cff_sessions - Found carriedforward")
753778
return True
754-
log.info("_has_cff_sessions - No carriedforward")
755779
return False
756780

757781
@property

services/tests/test_comparison.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -925,13 +925,17 @@ def test_head_and_base_reports_have_cff_sessions(
925925
fc = self.comparison.has_different_number_of_head_and_base_sessions
926926
assert fc == False
927927

928+
@patch(
929+
"services.comparison.Comparison.head_report_without_applied_diff",
930+
new_callable=PropertyMock,
931+
)
928932
def test_head_and_base_reports_have_different_number_of_reports(
929-
self, base_report_mock, head_report_mock, _
933+
self, head_report_no_diff_mock, base_report_mock, head_report_mock, _
930934
):
931935
# Only relevant files keys to the session object
932936
head_report_sessions = {"0": {"st": "uploaded"}, "1": {"st": "uploaded"}}
933937
head_report = SerializableReport(sessions=head_report_sessions)
934-
head_report_mock.return_value = head_report
938+
head_report_no_diff_mock.return_value = head_report
935939
base_report_sessions = {"0": {"st": "uploaded"}}
936940
base_report = SerializableReport(sessions=base_report_sessions)
937941
base_report_mock.return_value = base_report

0 commit comments

Comments
 (0)