diff --git a/tests/webapp/api/test_perfcompare_api.py b/tests/webapp/api/test_perfcompare_api.py index 8cc6534cab0..3d0b0477034 100644 --- a/tests/webapp/api/test_perfcompare_api.py +++ b/tests/webapp/api/test_perfcompare_api.py @@ -151,6 +151,7 @@ def test_perfcompare_results_against_no_base( "is_regression": response["is_regression"], "is_meaningful": response["is_meaningful"], "parent_signature": response["parent_signature"], + "signature_id": response["signature_id"], }, ] @@ -309,6 +310,7 @@ def test_perfcompare_results_with_only_one_run_and_diff_repo( "is_regression": response["is_regression"], "is_meaningful": response["is_meaningful"], "parent_signature": response["parent_signature"], + "signature_id": response["signature_id"], }, ] @@ -471,6 +473,7 @@ def test_perfcompare_results_subtests_support( "is_regression": response["is_regression"], "is_meaningful": response["is_meaningful"], "parent_signature": response["parent_signature"], + "signature_id": response["signature_id"], }, ] @@ -815,4 +818,5 @@ def get_expected( response["parent_signature"] = ( base_sig.parent_signature.id if base_sig.parent_signature else None ) + response["signature_id"] = base_sig.id return response diff --git a/treeherder/webapp/api/performance_data.py b/treeherder/webapp/api/performance_data.py index 92886c1b0ad..d6ec28cb6f4 100644 --- a/treeherder/webapp/api/performance_data.py +++ b/treeherder/webapp/api/performance_data.py @@ -1061,6 +1061,7 @@ def list(self, request): "parent_signature": parent_signature if parent_signature else base_sig.get("parent_signature_id", None), + "signature_id": base_sig_id, } self.queryset.append(row_result) @@ -1093,8 +1094,13 @@ def _get_push_timestamp(base_push, new_push): break return max(values) - def _get_perf_data(self, repository_name, revision, signatures, interval, startday, endday): - perf_data = self._get_perf_data_by_repo_and_signatures(repository_name, signatures) + @staticmethod + def _get_perf_data(repository_name, revision, signatures, interval, startday, endday): + signature_ids = [signature["id"] for signature in list(signatures)] + perf_data = PerformanceDatum.objects.select_related("push", "repository", "id").filter( + signature_id__in=signature_ids, + repository__name=repository_name, + ) if revision: perf_data = perf_data.filter(push__revision=revision) elif interval and not startday and not endday: @@ -1108,16 +1114,37 @@ def _get_perf_data(self, repository_name, revision, signatures, interval, startd return perf_data - def _get_signatures(self, repository_name, framework, parent_signature, interval, no_subtests): - signatures = self._get_filtered_signatures_by_repo(repository_name) + @staticmethod + def _get_signatures(repository_name, framework, parent_signature, interval, no_subtests): + signatures = PerformanceSignature.objects.select_related( + "framework", "repository", "platform", "push", "job" + ).filter(repository__name=repository_name) signatures = signatures.filter(parent_signature__isnull=no_subtests) if framework: signatures = signatures.filter(framework__id=framework) if parent_signature: signatures = signatures.filter(parent_signature_id=parent_signature) if interval: - signatures = self._get_filtered_signatures_by_interval(signatures, interval) - signatures = self._get_signatures_values(signatures) + signatures = signatures.filter( + last_updated__gte=datetime.datetime.utcfromtimestamp( + int(time.time() - int(interval)) + ) + ) + signatures = signatures.values( + "framework_id", + "id", + "extra_options", + "suite", + "platform__platform", + "test", + "option_collection_id", + "parent_signature_id", + "repository_id", + "measurement_unit", + "lower_is_better", + "signature_hash", + "application", + ) return signatures @staticmethod @@ -1174,44 +1201,6 @@ def _get_interval(base_push, new_push): break return new_time_range - @staticmethod - def _get_perf_data_by_repo_and_signatures(repository_name, signatures): - signature_ids = [signature["id"] for signature in list(signatures)] - return PerformanceDatum.objects.select_related("push", "repository", "id").filter( - signature_id__in=signature_ids, - repository__name=repository_name, - ) - - @staticmethod - def _get_filtered_signatures_by_interval(signatures, interval): - return signatures.filter( - last_updated__gte=datetime.datetime.utcfromtimestamp(int(time.time() - int(interval))) - ) - - @staticmethod - def _get_signatures_values(signatures): - return signatures.values( - "framework_id", - "id", - "extra_options", - "suite", - "platform__platform", - "test", - "option_collection_id", - "parent_signature_id", - "repository_id", - "measurement_unit", - "lower_is_better", - "signature_hash", - "application", - ) - - @staticmethod - def _get_filtered_signatures_by_repo(repository_name): - return PerformanceSignature.objects.select_related( - "framework", "repository", "platform", "push", "job" - ).filter(repository__name=repository_name) - @staticmethod def _get_grouped_perf_data(perf_data): grouped_values = defaultdict(list) @@ -1222,7 +1211,8 @@ def _get_grouped_perf_data(perf_data): grouped_job_ids[signature_id].append(job_id) return grouped_job_ids, grouped_values - def _get_signatures_map(self, signatures, grouped_values, option_collection_map): + @staticmethod + def _get_signatures_map(signatures, grouped_values, option_collection_map): """ @return: signatures_map - contains a mapping of all the signatures for easy access and matching header_names - list of header names for all given signatures diff --git a/treeherder/webapp/api/performance_serializers.py b/treeherder/webapp/api/performance_serializers.py index 69a779ac57b..8ba7a747ff1 100644 --- a/treeherder/webapp/api/performance_serializers.py +++ b/treeherder/webapp/api/performance_serializers.py @@ -546,6 +546,7 @@ class PerfCompareResultsSerializer(serializers.ModelSerializer): is_regression = serializers.BooleanField(required=False) is_meaningful = serializers.BooleanField(required=False) parent_signature = serializers.IntegerField() + signature_id = serializers.IntegerField() class Meta: model = PerformanceSignature @@ -594,6 +595,7 @@ class Meta: "is_regression", "is_meaningful", "parent_signature", + "signature_id", ]