From fa7bd8e9ec69cae3d43f5350a28016905701c3d9 Mon Sep 17 00:00:00 2001 From: Pablo Date: Wed, 13 Nov 2024 10:19:37 +0100 Subject: [PATCH] fix: [ANDROAPP-6398] Tei dashbard takes too long to load if option set is too big (#3851) * fix: [ANDROAPP-6398] Tei dashbard takes too long to load if option set is too big Signed-off-by: Pablo * fix sonarcloud warnings Signed-off-by: Pablo * remove unused code * fix unit test --------- Signed-off-by: Pablo --- .../teidata/TEIDataFragment.kt | 2 +- .../teidata/TeiDataRepositoryImpl.kt | 2 +- .../TroubleshootingRepository.kt | 1 - .../RuleEngineExtensions.kt | 49 +++---------------- .../mobileProgramRules/RulesRepository.kt | 15 ------ .../RuleEngineExtensionsTest.kt | 1 - .../rules/RuleValidationHelperImpl.kt | 1 - 7 files changed, 10 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt index c6b19480ad..657a53312c 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt @@ -139,7 +139,7 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { return FragmentTeiDataBinding.inflate(inflater, container, false).also { binding -> this.binding = binding dashboardViewModel.groupByStage.observe(viewLifecycleOwner) { group -> - showLoadingProgress(false) + showLoadingProgress(true) presenter.onGroupingChanged(group) } diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TeiDataRepositoryImpl.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TeiDataRepositoryImpl.kt index c003fc5430..7e8227b954 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TeiDataRepositoryImpl.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TeiDataRepositoryImpl.kt @@ -441,7 +441,7 @@ class TeiDataRepositoryImpl( override fun displayOrganisationUnit(programUid: String): Boolean { return d2.organisationUnitModule().organisationUnits() .byProgramUids(listOf(programUid)) - .blockingGet().size > 1 + .blockingCount() > 1 } override fun enrollmentOrgUnitInCaptureScope(enrollmentOrgUnit: String): Boolean { diff --git a/app/src/main/java/org/dhis2/usescases/troubleshooting/TroubleshootingRepository.kt b/app/src/main/java/org/dhis2/usescases/troubleshooting/TroubleshootingRepository.kt index 001af922db..f0b44329d9 100644 --- a/app/src/main/java/org/dhis2/usescases/troubleshooting/TroubleshootingRepository.kt +++ b/app/src/main/java/org/dhis2/usescases/troubleshooting/TroubleshootingRepository.kt @@ -108,7 +108,6 @@ class TroubleshootingRepository( .blockingGet().toRuleVariableList( d2.trackedEntityModule().trackedEntityAttributes(), d2.dataElementModule().dataElements(), - d2.optionModule().options(), ).mapNotNull { val ruleValueType = it.fieldType val valueKey = when (it) { diff --git a/dhis2-mobile-program-rules/src/main/java/org/dhis2/mobileProgramRules/RuleEngineExtensions.kt b/dhis2-mobile-program-rules/src/main/java/org/dhis2/mobileProgramRules/RuleEngineExtensions.kt index 0289d3ca7a..7f64d9b8f5 100644 --- a/dhis2-mobile-program-rules/src/main/java/org/dhis2/mobileProgramRules/RuleEngineExtensions.kt +++ b/dhis2-mobile-program-rules/src/main/java/org/dhis2/mobileProgramRules/RuleEngineExtensions.kt @@ -61,10 +61,9 @@ fun List.toRuleActionList(): List { fun List.toRuleVariableList( attributeRepository: TrackedEntityAttributeCollectionRepository, dataElementRepository: DataElementCollectionRepository, - optionRepository: OptionCollectionRepository, ): List { - return filter { - when { + return mapNotNull { + val allowVariable = when { it.dataElement() != null -> { dataElementRepository.uid(it.dataElement()?.uid()).blockingExists() } @@ -75,8 +74,11 @@ fun List.toRuleVariableList( else -> isCalculatedValue(it) } - }.map { - it.toRuleVariable(attributeRepository, dataElementRepository, optionRepository) + if (allowVariable) { + it.toRuleVariable(attributeRepository, dataElementRepository) + } else { + null + } } } @@ -325,7 +327,6 @@ fun ProgramRuleAction.toRuleEngineObject(): RuleAction { fun ProgramRuleVariable.toRuleVariable( attributeRepository: TrackedEntityAttributeCollectionRepository, dataElementRepository: DataElementCollectionRepository, - optionRepository: OptionCollectionRepository, ): RuleVariable { val valueType = when (programRuleVariableSourceType()) { ProgramRuleVariableSourceType.DATAELEMENT_NEWEST_EVENT_PROGRAM_STAGE, @@ -348,14 +349,7 @@ fun ProgramRuleVariable.toRuleVariable( } val useCodeForOptionSet = useCodeForOptionSet() ?: false - val options = getOptions( - useCodeForOptionSet, - dataElement()?.uid(), - trackedEntityAttribute()?.uid(), - attributeRepository, - dataElementRepository, - optionRepository, - ) + val options = emptyList