Skip to content

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

Closed
alexandr-simprints wants to merge 1 commit into
mainfrom
MS-923-fix-the-text-below-the-identification-progress-bar
Closed

[MS-923] Adding internal counter for the amount of loaded candidates in the MatchViewModel#1125
alexandr-simprints wants to merge 1 commit into
mainfrom
MS-923-fix-the-text-below-the-identification-progress-bar

Conversation

@alexandr-simprints
Copy link
Copy Markdown
Contributor

@alexandr-simprints alexandr-simprints commented Mar 4, 2025

Closed due to targeting incorrect branch. Correct branch is set here: PR 1126

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 4, 2025

@alexandr-simprints alexandr-simprints changed the base branch from main to release/2025.1.0 March 5, 2025 07:28
@alexandr-simprints alexandr-simprints changed the base branch from release/2025.1.0 to main March 5, 2025 07:28
@alexandr-simprints
Copy link
Copy Markdown
Contributor Author

Closing this PR, since it targets main instead of release/2025.1.0

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