Есть такой код
    @GetMapping("/context/sections")
    @Operation(summary = "ЛСР получение контекста. Уровень секций")
    fun getLocalContextBySections(
        @PathVariable id: UUID,
        @RequestParam(defaultValue = "0") page: Int,
        @RequestParam(defaultValue = "10") pageSize: Int,
        @RequestParam(required = false, defaultValue = "false") tsn: Boolean,
        @RequestParam(required = false, defaultValue = "false") calculations: Boolean,
    ): Page<SectionDto> = localContextService.getSections(id, page, pageSize, tsn, calculations)

    fun getSections(estimateId: UUID, page: Int, pageSize: Int,
                    tsn: Boolean = false,
                    calculations: Boolean = false): Page<SectionDto> {
        val pageable: Pageable = PageRequest.of(page, pageSize)
        return localSectionRepository.findAllByEstimateId(estimateId, tsn, calculations, pageable)
            .map { section ->
                SectionDto(
                    id = section.jsonSectionData.id,
                    code = section.jsonSectionData.code,
                    name = section.jsonSectionData.name,
                    comment = section.jsonSectionData.comment,
                    positions = section.jsonSectionData.positions,
                    total = section.jsonSectionData.total,
                    totalReturn = section.jsonSectionData.totalReturn,
                    totalDetails = section.jsonSectionData.totalDetails,
                )
            }
    }

@Repository
interface LocalSectionRepository : JpaRepository<LocalSection, UUID> {
    @Query("""
        SELECT s FROM LocalSection s 
        JOIN s.localContext lc 
        WHERE lc.estimate.id = :estimateId
        AND (
            (:tsn = false AND :calculations = false)
            OR
            (:tsn = true AND :calculations = true AND s.errorsCount > 0 
                OR EXISTS(SELECT 1 FROM LocalPosition p WHERE p.section = s AND p.errorsCountTsn > 0)
                OR EXISTS(SELECT 1 FROM LocalPosition p WHERE p.section = s AND p.errorsCountCalculation > 0)
            )
            OR
            (:tsn = true AND EXISTS(
                SELECT 1 FROM LocalPosition p
                WHERE p.section = s AND p.errorsCountTsn > 0
            ))
            OR
            (:calculations = true AND EXISTS (
                SELECT 1 FROM LocalPosition p
                WHERE p.section = s AND p.errorsCountCalculation > 0
            ))
        )
    """)
    fun findAllByEstimateId(
        @Param("estimateId") estimateId: UUID,
        @Param("tsn") tsn: Boolean,
        @Param("calculations") calculations: Boolean,
        pageable: Pageable
    ): Page<LocalSection>
}

package ru.mge.estimate.model.local.dto

import ru.mge.estimate.model.ValueType
import ru.mge.estimate.model.local.*
import java.util.*

data class LocalContextBriefDto(
    val meta: LocalMetaDto,
    val summary: LocalSummaryDto,
    val parameters: ParametersBriefDto
)

data class SectionBriefDto(
    val id: UUID,
    val code: ValueType.IntegerValue,
    val name: ValueType.StringValue,
)

data class PositionBriefDto(
    val id: UUID,
)

data class LocalContextDto(
    val id: UUID,
    val meta: LocalMetaDto,
    val summary: LocalSummaryDto,
    val sections: List<SectionBriefDto>,
    val parameters: ParametersDto
)

data class LocalMetaDto(
    val softName: ValueType.StringValue,
    val softVersion: ValueType.StringValue,
    val estimateNum: ValueType.StringValue,
    val estimateName: ValueType.StringValue,
    val estimateReason: ValueType.StringValue,
    val normativeName: ValueType.StringValue,
    val normativeAdditionNumber: ValueType.IntegerValue,
    val estimateTotal: EstimateTotalDto,
    val composerName: ValueType.StringValue,
    val verifierName: ValueType.StringValue,
    val constructionNum: ValueType.StringValue,
    val constructionName: ValueType.StringValue,
    val objectName: ValueType.StringValue,
    val priceLevelBaseYear: ValueType.IntegerValue,
    val priceLevelBaseQuarter: ValueType.IntegerValue,
    val priceLevelBaseMonth: ValueType.IntegerValue,
    val priceLevelBaseOverheadMachinist: ValueType.DecimalValue,
    val priceLevelBaseProfitMachinist: ValueType.DecimalValue,
    val priceLevelBaseDescription: ValueType.StringValue,
    val priceLevelBaseNote: ValueType.StringValue,
    val priceLevelCurYear: ValueType.IntegerValue,
    val priceLevelCurQuarter: ValueType.IntegerValue,
    val priceLevelCurMonth: ValueType.IntegerValue,
    val priceLevelCurOverheadMachinist: ValueType.DecimalValue,
    val priceLevelCurProfitMachinist: ValueType.DecimalValue,
    val priceLevelCurDescription: ValueType.StringValue,
    val priceLevelCurNote: ValueType.StringValue,
    val priceDescription: ValueType.StringValue,
)

data class LocalSummaryDto(
    val building: SummaryValueDto,
    val mounting: SummaryValueDto,
    val equipment: SummaryValueDto,
    val otherPrice: SummaryValueDto,
    val summarySalary: SummaryValueDto,
    val summaryLaborCost: ValueType.DecimalValue,
    val returnSummaryValue: SummaryValueDto,
    val totalPrice: SummaryValueDto,
)

data class EstimateTotalDto(
    val summary: EstimateTotalValueDto,
    val building: EstimateTotalValueDto,
    val buildingMaterial: EstimateTotalValueDto,
    val buildingMachinesPrice: EstimateTotalValueDto,
    val mounting: EstimateTotalValueDto,
    val mountingMaterial: EstimateTotalValueDto,
    val mountingMachinesPrice: EstimateTotalValueDto,
)

data class EstimateTotalValueDto(
    val base: ValueType.DecimalValue? = null,
    val current: ValueType.DecimalValue? = null,
)

data class SummaryValueDto(
    val base: ValueType.DecimalValue? = null,
    val current: ValueType.DecimalValue? = null,
)

data class SectionDto(
    val id: UUID,
    val code: ValueType.IntegerValue,
    val name: ValueType.StringValue,
    val comment: ValueType.StringValue,
    val positions: List<PositionBriefDto>,
    val total: TotalDataDto,
    val totalReturn: TotalDataDto,
    val totalDetails: EstimateTotalDto
)

data class PositionDto(
    val workType: ValueType.StringValue,
    val totalWork: TotalDataDto,
    val isReturnMat: Boolean?,
    val comment: ValueType.StringValue,
    val totalEquipment: TotalDataDto,
    val totalPosition: TotalDataDto,
    val workersOverhead: WorkerDataDto,
    val workersProfit: WorkerDataDto,
    val machinistOverheadProfit: WorkerDataDto,
    val laborCosts: WorkerDataDto,
    val groundVolume: WorkerDataDto,
    val groundWeight: WorkerDataDto,
    val garbageWeight: WorkerDataDto,
    val equipmentWeight: WorkerDataDto,
    val tsn: List<TsnDto>,
)

data class TsnDto(
    val type: ValueType.ItemType,
    val num: ValueType.IntegerValue,
    val prefix: ValueType.StringValue,
    val code: ValueType.StringValue,
    val comment: ValueType.StringValue,
    val quantityFormula: ValueType.StringValue,
    val quantityTotal: ValueType.DecimalValue,
    val name: ValueType.StringValue,
    val unit: ValueType.StringValue,
    val consumptionTotal: ValueType.DecimalValue,
    val pricePerUnitBase: ValueType.DecimalValue,
    val coefficients: List<CoefficientDto>,
    val winterRise: ValueType.DecimalValue,
    val totalBase: ValueType.DecimalValue,
    val recountCoefficients: List<ValueType.DecimalValue>,
    val recountCoefficientsSum: ValueType.DecimalValue,
    val totalCurrent: ValueType.DecimalValue,
    val workersSalary: WorkerDataDto,
    val machineOperation: WorkerDataDto,
    val machinistSalary: WorkerDataDto,
    val tsn: List<TsnDto> = emptyList(),
    val materialResources: WorkerDataDto,
    val equipmentCosts: WorkerDataDto,
    val otherCosts: WorkerDataDto,
    val pricePerUnitCurrent: ValueType.DecimalValue,
)

data class WorkerDataDto(
    val unit: ValueType.StringValue,
    val consumptionTotal: ValueType.DecimalValue,
    val pricePerUnitBase: ValueType.DecimalValue,
    val pricePerUnitCurrent: ValueType.DecimalValue,
    val coefficients: List<CoefficientDto>,
    val winterRise: ValueType.DecimalValue,
    val totalBase: ValueType.DecimalValue,
    val recountCoefficients: List<ValueType.DecimalValue>,
    val recountCoefficientsSum: ValueType.DecimalValue,
    val totalCurrent: ValueType.DecimalValue,
)

data class CoefficientDto(
    val values: List<ValueType.DecimalValue>,
    val reason: ValueType.StringValue,
    val name: ValueType.StringValue,
)

data class TotalDataDto(
    val base: ValueType.DecimalValue? = null,
    val current: ValueType.DecimalValue? = null,
)

data class ParametersDto(
    val okn: Boolean,
    val form19: Boolean = false,
    val index: Int? = null,
    val indexEquipment: Int? = null,
    val additionNumber: Int? = null,
    val additionNumberEquipment: Int? = null,
    val constructionDescription: ValueType.StringValue
)

data class ParametersBriefDto(
    val description: ValueType.StringValue,
)

fun LocalConstructionContext.toLocalContextBriefDto(): LocalContextBriefDto =
    LocalContextBriefDto(
        meta = this.meta.toParametersBriefDto(),
        summary = this.summary.toParametersBriefDto(),
        parameters = this.parameters.toParametersBriefDto(),
    )

fun Section.toParametersBriefDto(id: UUID): SectionDto =
    SectionDto(
        id = id,
        code = this.code,
        name = this.name,
        comment = this.comment,
        positions = this.position.map { it.toPositionBriefDto(id) },
        total = this.total.toParametersBriefDto(),
        totalReturn = this.totalReturn.toParametersBriefDto(),
        totalDetails = this.totalDetails.toParametersBriefDto()
    )

fun Section.toSectionBriefDto(id: UUID) : SectionBriefDto =
    SectionBriefDto(
        id = id,
        code = this.code,
        name = this.name,
    )

fun LocalMeta.toParametersBriefDto(): LocalMetaDto =
    LocalMetaDto(
        softName = this.softName,
        softVersion = this.softVersion,
        estimateNum = this.estimateNum,
        estimateName = this.estimateName,
        estimateReason = this.estimateReason,
        normativeName = this.normativeName,
        normativeAdditionNumber = this.normativeAdditionNumber,
        estimateTotal = this.estimateTotal.toParametersBriefDto(),
        composerName = this.composerName,
        verifierName = this.verifierName,
        constructionNum = this.constructionNum,
        constructionName = this.constructionName,
        objectName = this.objectName,
        priceLevelBaseYear = this.priceLevelBaseYear,
        priceLevelBaseQuarter = this.priceLevelBaseQuarter,
        priceLevelBaseMonth = this.priceLevelBaseMonth,
        priceLevelBaseOverheadMachinist = this.priceLevelBaseOverheadMachinist,
        priceLevelBaseProfitMachinist = this.priceLevelBaseProfitMachinist,
        priceLevelBaseDescription = this.priceLevelBaseDescription,
        priceLevelBaseNote = this.priceLevelBaseNote,
        priceLevelCurYear = this.priceLevelCurYear,
        priceLevelCurQuarter = this.priceLevelCurQuarter,
        priceLevelCurMonth = this.priceLevelCurMonth,
        priceLevelCurOverheadMachinist = this.priceLevelCurOverheadMachinist,
        priceLevelCurProfitMachinist = this.priceLevelCurProfitMachinist,
        priceLevelCurDescription = this.priceLevelCurDescription,
        priceLevelCurNote = this.priceLevelCurNote,
        priceDescription = this.priceDescription
    )

fun LocalSummary.toParametersBriefDto(): LocalSummaryDto =
    LocalSummaryDto(
        building = this.building.toParametersBriefDto(),
        mounting = this.mounting.toParametersBriefDto(),
        equipment = this.equipment.toParametersBriefDto(),
        otherPrice = this.otherPrice.toParametersBriefDto(),
        summarySalary = this.summarySalary.toParametersBriefDto(),
        summaryLaborCost = this.summaryLaborCost,
        returnSummaryValue = this.returnSummaryValue.toParametersBriefDto(),
        totalPrice = this.totalPrice.toParametersBriefDto()
    )

fun SummaryValue.toParametersBriefDto(): SummaryValueDto =
    SummaryValueDto(
        base = this.base,
        current = this.current
    )

fun EstimateTotal.toParametersBriefDto(): EstimateTotalDto =
    EstimateTotalDto(
        summary = this.summary.toParametersBriefDto(),
        building = building.toParametersBriefDto(),
        buildingMaterial = this.buildingMaterial.toParametersBriefDto(),
        buildingMachinesPrice = this.buildingMachinesPrice.toParametersBriefDto(),
        mounting = this.mounting.toParametersBriefDto(),
        mountingMaterial = this.mountingMaterial.toParametersBriefDto(),
        mountingMachinesPrice = this.mountingMachinesPrice.toParametersBriefDto()
    )

fun EstimateTotalValue.toParametersBriefDto(): EstimateTotalValueDto =
    EstimateTotalValueDto(
        base = this.base,
        current = this.current
    )

fun Position.toPositionBriefDto(id: UUID): PositionBriefDto =
    PositionBriefDto(
        id = id,
    )

fun Position.toParametersBriefDto(): PositionDto =
    PositionDto(
        workType = this.workType,
        totalWork = this.totalWork.toParametersBriefDto(),
        isReturnMat = this.isReturnMat,
        comment = this.comment,
        totalEquipment = this.totalEquipment.toParametersBriefDto(),
        totalPosition = this.totalPosition.toParametersBriefDto(),
        workersOverhead = this.workersOverhead.toParametersBriefDto(),
        workersProfit = this.workersProfit.toParametersBriefDto(),
        machinistOverheadProfit = this.machinistOverheadProfit.toParametersBriefDto(),
        laborCosts = this.laborCosts.toParametersBriefDto(),
        groundVolume = this.groundVolume.toParametersBriefDto(),
        groundWeight = this.groundWeight.toParametersBriefDto(),
        garbageWeight = this.garbageWeight.toParametersBriefDto(),
        equipmentWeight = this.equipmentWeight.toParametersBriefDto(),
        tsn = this.tsn.map { it.toParametersBriefDto() }
    )

fun TotalData.toParametersBriefDto(): TotalDataDto =
    TotalDataDto(
        base = this.base,
        current = this.current
    )

fun WorkerData.toParametersBriefDto(): WorkerDataDto =
    WorkerDataDto(
        unit = this.unit,
        consumptionTotal = this.consumptionTotal,
        pricePerUnitBase = this.pricePerUnitBase,
        pricePerUnitCurrent = this.pricePerUnitCurrent,
        coefficients = this.coefficients.map { it.toParametersBriefDto() },
        winterRise = this.winterRise,
        totalBase = this.totalBase,
        recountCoefficients = this.recountCoefficients.map { it },
        recountCoefficientsSum = this.recountCoefficientsSum,
        totalCurrent = this.totalCurrent
    )

fun Coefficient.toParametersBriefDto(): CoefficientDto =
    CoefficientDto(
        values = this.values,
        reason = this.reason,
        name = this.name
    )

fun Tsn.toParametersBriefDto(): TsnDto =
    TsnDto(
        type = this.type,
        num = this.num,
        prefix = this.prefix,
        code = this.code,
        comment = this.comment,
        quantityFormula = this.quantityFormula,
        quantityTotal = this.quantityTotal,
        name = this.name,
        unit = this.unit,
        consumptionTotal = this.consumptionTotal,
        pricePerUnitBase = this.pricePerUnitBase,
        coefficients = this.coefficients.map { it.toParametersBriefDto() },
        winterRise = this.winterRise,
        totalBase = this.totalBase,
        recountCoefficients = this.recountCoefficients,
        recountCoefficientsSum = this.recountCoefficientsSum,
        totalCurrent = this.totalCurrent,
        workersSalary = this.workersSalary.toParametersBriefDto(),
        machineOperation = this.machineOperation.toParametersBriefDto(),
        machinistSalary = this.machinistSalary.toParametersBriefDto(),
        tsn = this.tsn.map { it.toParametersBriefDto() },
        materialResources = this.materialResources.toParametersBriefDto(),
        equipmentCosts = this.equipmentCosts.toParametersBriefDto(),
        otherCosts = this.otherCosts.toParametersBriefDto(),
        pricePerUnitCurrent = this.pricePerUnitCurrent
    )

fun Parameters.toParametersBriefDto(): ParametersBriefDto =
    ParametersBriefDto(
            description = this.constructionDescription
        )
При применении одного из фильтров или обоих в запросе, запрос зависает