def _get_job_list_response()

in treeherder/webapp/api/jobs.py [0:0]


    def _get_job_list_response(self, job_qs, offset, count, return_type):
        """
        custom method to serialize + format jobs information

        It's worth doing this big ugly thing (as opposed to using
        the django rest framework serializer or whatever) as
        this function is often in the critical path
        """
        option_collection_map = OptionCollection.objects.get_option_collection_map()
        results = []
        for values in job_qs[offset : (offset + count)].values_list(
            *[pq[1] for pq in self._property_query_mapping]
        ):
            platform_option = option_collection_map.get(
                values[self._option_collection_hash_idx], ""
            )
            # some values need to be transformed
            values = list(values)
            for i, _ in enumerate(values):
                func = self._property_query_mapping[i][2]
                if func:
                    values[i] = func(values[i])
            # append results differently depending on if we are returning
            # a dictionary or a list
            if return_type == "dict":
                results.append(
                    dict(
                        zip(
                            [pq[0] for pq in self._property_query_mapping] + ["platform_option"],
                            values + [platform_option],
                        )
                    )
                )
            else:
                results.append(values + [platform_option])

        response_dict = {"results": results}
        if return_type == "list":
            response_dict.update(
                {
                    "job_property_names": [pq[0] for pq in self._property_query_mapping]
                    + ["platform_option"]
                }
            )

        return response_dict