Skip to content

Fix Home row requests continuing after Home reloads - #2196

Open
AJadkarim wants to merge 1 commit into
damontecres:mainfrom
AJadkarim:fix-home-row-jobs-cancel
Open

AJadkarim wants to merge 1 commit into
damontecres:mainfrom
AJadkarim:fix-home-row-jobs-cancel

Conversation

@AJadkarim

Copy link
Copy Markdown

Description

In HomeViewModel, when a user switches profiles or changes Home settings while rows are loading, dataLoadingJob?.cancel() cancels the top-level loading job. However, individual row fetches were launched on viewModelScope.async(WholphinDispatchers.IO) without being attached to the dataLoadingJob coroutine hierarchy. As a result, cancelling dataLoadingJob stopped awaiting the rows, but left the underlying HTTP requests and row fetches continuing to execute in the background on viewModelScope. In addition, loadHomeRows caught general Exception inside each row's async block, causing any CancellationException to be swallowed and mapped into HomeRowLoadingState.Error instead of propagating cancellation.

This PR wraps the row fetch launches and collection in coroutineScope { ... }, launches row fetches with async(WholphinDispatchers.IO) so they are bound to that scope, and explicitly rethrows CancellationException. When dataLoadingJob is cancelled, all in-flight row fetches are cancelled immediately. The scope parameter passed to fetchDataForRow remains viewModelScope so downstream pagers (ApiRequestPager) and image lookups remain active after initial loading completes.

Related issues

I searched existing issues and pull requests on damontecres/Wholphin for HomeViewModel, loadHomeRows, dataLoadingJob, CancellationException, and Home row cancellation and did not find an existing issue or pull request for this behavior.

Steps to reproduce:

  1. Open Wholphin on a server with multiple libraries and configured Home rows.
  2. Quickly switch users or toggle Home row settings while rows are actively loading over the network.
  3. Observe network traffic or logging: previously triggered row HTTP fetches continue completing in the background despite the Home reload, wasting bandwidth and server resources.

Testing

  • Unit tests: 3 unit tests in TestHomeRowJobs:
    • cancellingLoadCancelsInFlightRowRequests: verifies that cancelling a running loadHomeRows job cancels in-flight fetchDataForRow calls before they complete.
    • cancellationExceptionIsNotMappedToRowError: verifies that when fetchDataForRow throws CancellationException, cancellation propagates cleanly instead of mapping the row to HomeRowLoadingState.Error.
    • rowScopeRemainsViewModelScopeAfterLoadCompletes: verifies that after loadHomeRows completes normally, the CoroutineScope passed to fetchDataForRow is viewModelScope and remains active.
  • Negative control: verified that TestHomeRowJobs fails on unfixed base code (v1.1.1 / 159edc87) and passes cleanly with this change.
  • Existing tests: ran TestHomeRowSamples alongside TestHomeRowJobs to confirm zero regressions in existing Home row behaviors.
  • ktlint: clean (0 errors) on modified files.

Screenshots

None (no UI change).

AI or LLM usage

I used AI tools for this change: OpenAI Codex identified the issue in an earlier larger Home change, and Google Gemini through drafted this fix, unit tests, and review. This covers the changes in HomeViewModel.kt and TestHomeRowJobs.kt.

I tested the change with the unit tests above and ktlint. I have reviewed and understand the changes in this pull request and take responsibility for them.

Wrap loadHomeRows row async jobs in coroutineScope and rethrow CancellationException while retaining viewModelScope for fetchDataForRow.

Assisted-by: agy:gemini-3.8-flash-high

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant