def _get_by_id(
        self,
        resource_id,
        exclude_fields=None,
        include_fields=None,
        max_result_size=None,
    ):
        """
        Custom version of _get_by_id() which supports ?max_result_size pre-filtering and not
        returning result field for executions which result size exceeds this threshold.

        This functionality allows us to implement fast and efficient retrievals in st2web.
        """
        exclude_fields = exclude_fields or []
        include_fields = include_fields or []

        if not max_result_size:
            # If max_result_size is not provided we don't perform any prefiltering and directly
            # call parent method
            execution_db = super(ActionExecutionsController, self)._get_by_id(
                resource_id=resource_id,
                exclude_fields=exclude_fields,
                include_fields=include_fields,
            )
            return execution_db

        # Special query where we check if result size is smaller than pre-defined or that field
        # doesn't not exist (old executions) and only return the result if the condition is met.
        # This allows us to implement fast and efficient retrievals of executions on the client
        # st2web side where we don't want to retrieve and display result directly for executions
        # with large results
        # Keep in mind that the query itself is very fast and adds almost no overhead for API
        # operations which pass this query parameter because we first filter on the ID (indexed
        # field) and perform projection query with two tiny fields (based on real life testing it
        # takes less than 3 ms in most scenarios).
        execution_db = self.access.get(
            Q(id=resource_id)
            & (Q(result_size__lte=max_result_size) | Q(result_size__not__exists=True)),
            only_fields=["id", "result_size"],
        )

        # if result is empty, this means that execution either doesn't exist or the result is
        # larger than threshold which means we don't want to retrieve and return result to
        # the end user to we set exclude_fields accordingly
        if not execution_db:
            LOG.debug(
                "Execution with id %s and result_size < %s not found. This means "
                "execution with this ID doesn't exist or result_size exceeds the "
                "threshold. Result field will be excluded from the retrieval and "
                "the response." % (resource_id, max_result_size)
            )

            if include_fields and "result" in include_fields:
                include_fields.remove("result")
            elif not include_fields:
                exclude_fields += ["result"]

        # Now call parent get by id with potentially modified include / exclude fields in case
        # result should not be included
        execution_db = super(ActionExecutionsController, self)._get_by_id(
            resource_id=resource_id,
            exclude_fields=exclude_fields,
            include_fields=include_fields,
        )
        return execution_db

        Custom version of _get_by_id() which supports ?max_result_size pre-filtering and not
        returning result field for executions which result size exceeds this threshold.

        This functionality allows us to implement fast and efficient retrievals in st2web.
        
st2api/st2api/controllers/v1/actionexecutions.py