Skip to content

Paged loads don't emit background load status in metadata while the first page is loading #22

Description

@romychab

Summary

When using PagedStore (store lib) or pagedLoader (container lib), the backgroundLoadState exposed via Container / StoreResult metadata is not set to BackgroundLoadState.Loading while the first page is being (re)loaded in the background. Consumers relying on metadata.backgroundLoadState (or StoreResult.isBackgroundLoading()) to drive a "refreshing" indicator get Idle during the initial page load, so the background-load signal is effectively swallowed for paged sources.

Expected behavior

While a paged source is loading its first page in the background (e.g. a silent reload/invalidate while content is still visible), emissions should carry BackgroundLoadState.Loading in their metadata, consistent with non-paged sources (FlowEmitter / StatefulEmitterImpl already do this).

Actual behavior

Paged emissions hardcode a base BackgroundLoadState.Idle. In-flight page loading is only represented through NextPageStateMetadata / PageState, never through BackgroundLoadState, so metadata.backgroundLoadState stays Idle for the first page.

Root cause / relevant code

  • container/src/main/java/com/elveum/container/subject/paging/internal/PageRecordsState.kt: emitUpdates() (~lines 137–178). The success path builds:
    val finalMetadata = BackgroundLoadMetadata(BackgroundLoadState.Idle) + ...
    This hardcodes Idle as the base and never injects Loading for an in-flight first-page load. The pending path (originEmitter.emitPendingState()) is the only place that can carry Loading, which doesn't cover the "content visible + first page reloading silently" case.
  • container/src/main/java/com/elveum/container/subject/paging/internal/PageLoaderImpl.kt:30: first page entry point (startLoading(pageIndex = 0, ...)await()emitCompletedState()).
  • Metadata plumbing that carries the state through to the store side: store/src/main/java/com/elveum/store/load/StoreResultContainerExtensions.kt and StoreResultExtensions.kt (isBackgroundLoading()).

Proposed fix

Propagate the session's background-loading status into PageRecordsState.emitUpdates() so that, while the first page load is in flight, the emitted BackgroundLoadMetadata reflects BackgroundLoadState.Loading instead of a hardcoded Idle (respecting configuration.emitBackgroundLoads).

Test gap

No test currently asserts backgroundLoadState / isBackgroundLoading() during the first page load of a paged store/loader. The existing paged assertion (store/src/test/java/com/elveum/store/paged/PagedStoreErrorsAndUpdatesTest.kt:97) only covers a silent async invalidate after the first load. Add coverage for the initial-page background-load case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions