Skip to content

[MS-923] Adding internal counter for the amount of loaded candidates in the MatchViewModel#1126

Merged
meladRaouf merged 1 commit into
release/2025.1.0from
MS-923-fix-the-text-below-the-identification-progress-bar-release
Mar 5, 2025
Merged

[MS-923] Adding internal counter for the amount of loaded candidates in the MatchViewModel#1126
meladRaouf merged 1 commit into
release/2025.1.0from
MS-923-fix-the-text-below-the-identification-progress-bar-release

Conversation

@alexandr-simprints
Copy link
Copy Markdown
Contributor

Issue description

The MatchViewModel observes the LoadingCandidates event from the Matcher UseCase and emits it to the LiveData's Observer. The LoadingCandidates event that might be emitted multiple times a second.

We've observed that the UI layer processed less than 5% of the events sent to the LiveData:

  • 43819 events emitted by the Use Case
  • 43819 events forwarded to the LiveData by the ViewModel (0% loss)
  • 2372 - received by the observer (MatchFragment, >90% loss)

Not only the events were being lost, the Observer stopped receiving them after some arbitrary threshold - after ~20 events on some devices, ~4000 events on others.

Fix

It was identified that by removing the state reference to itself for update, the issue disappears.

MatcherUseCase.MatcherState.CandidateLoaded -> {
    (_matchState.value as? MatchState.LoadingCandidates)?.let { currentState ->
        _matchState.postValue(currentState.copy(loaded = currentState.loaded + 1)) // changing this line
    }
}

was changed to

MatcherUseCase.MatcherState.CandidateLoaded -> {
    (_matchState.value as? MatchState.LoadingCandidates)?.let { currentState ->
        candidatesLoaded++
        _matchState.postValue(currentState.copy(loaded = candidatesLoaded))
    }
}

This way the new state does need to access old state for update, and no longer exhausts resources to send updates to the LiveData observer.

  • CoSync works ✅
  • SID local database works ✅

Video before the update:

callback-issue.mp4

Video after the update:

Local database

flow-counter.mp4

CoSync

cosync-counter-id.mp4

…in MatchViewModel. This way the new state does need to access old state for update, and no longer exhausts resources to send updates to the LiveData observer
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 5, 2025

@meladRaouf meladRaouf merged commit b69ace8 into release/2025.1.0 Mar 5, 2025
@meladRaouf meladRaouf deleted the MS-923-fix-the-text-below-the-identification-progress-bar-release branch March 5, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants