Skip to content

Media view count doesn't update for new files - blocked by thumbnail download queue #3974

@molycode

Description

@molycode

Description

The Media view's photo/video count doesn't update when new files are uploaded to the server. The count only updates when clearing the app cache. However, deleting a file DOES update the count immediately.

Steps to reproduce

  1. Open Nextcloud iOS app, go to Media view
  2. Note the count (e.g., "5207 Images • 630 Videos")
  3. Upload new photos from another device (or same device via auto-upload)
  4. Pull down to refresh / scroll around / close and reopen app
  5. Count remains unchanged
  6. Delete one photo from Media view
  7. Count decrements immediately (5206 Images)
  8. New uploads still don't appear until cache is cleared

Expected behavior

The Media view should discover and display new files when refreshing, and the count should update accordingly.

Actual behavior

  • Delete: Count updates immediately ✓
  • Add: Count stays stale until cache is cleared ✗

Root cause analysis (from source code review)

Examined the source code and found multiple issues in iOSClient/Media/:

1. No pull-to-refresh

NCMedia.swift has no UIRefreshControl - users cannot manually trigger a refresh.

2. searchMediaUI() blocked by thumbnail downloads

In NCMediaDataSource.swift:51-58:

guard self.isViewActived,
      !self.searchMediaInProgress,
      !self.isPinchGestureActive,
      !self.showOnlyImages,
      !self.showOnlyVideos,
      !self.isEditMode,
      self.networking.downloadThumbnailQueue.operationCount == 0 else {
    return false
}

The condition downloadThumbnailQueue.operationCount == 0 means searchMediaUI() is skipped whenever ANY thumbnails are being downloaded. When viewing a large photo library, thumbnails are always being fetched, so new file discovery never runs.

3. Delete bypasses the server fetch

In NCMedia+Command.swift:134:

self.dataSource.removeMetadata([ocId])
self.collectionView.deleteItems(at: [indexPath])

Delete directly modifies the dataSource without needing searchMediaUI(), which is why it works.

4. Full refresh only on cache clear

searchMediaUI(true) (which uses full date range) is only called on:

  • Account change (NCMedia.swift:138)
  • Cache clear (NCMedia.swift:146)

Normal scrolling calls searchMediaUI() with distant=false, which only fetches within the visible date range.

Suggested fix

  1. Add UIRefreshControl for pull-to-refresh that calls searchMediaUI(true)
  2. Remove or relax the downloadThumbnailQueue.operationCount == 0 condition
  3. Periodically check for new files regardless of thumbnail queue status

Environment

  • Nextcloud iOS app version: 7.2.2
  • Server: Nextcloud 32.0.5
  • iOS: 12.5.7 (iPhone 6) and iOS 17+ (iPhone 15) - same behavior on both
  • Server confirms files exist with correct metadata indexed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions