Skip to content

Commit

Permalink
Merge pull request #1036 from Infomaniak/debug-filelist
Browse files Browse the repository at this point in the history
feat: Add Sentry breadcrumb on file collection changes
  • Loading branch information
adrien-coye committed Oct 17, 2023
2 parents 6c77b35 + 6e7a74d commit 7ee60a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,11 @@ class FileListViewController: UIViewController, UICollectionViewDataSource, Swip
func updateFileList(deletions: [Int], insertions: [Int], modifications: [Int], moved: [(source: Int, target: Int)]) {
guard !(deletions.isEmpty && insertions.isEmpty && modifications.isEmpty && moved.isEmpty) else { return }

let reloadId = UUID().uuidString

collectionView.performBatchUpdates {
SentryDebug.updateFileListBreadcrumb(id: reloadId, step: "performBatchUpdates start")

// Always apply updates in the following order: deletions, insertions, then modifications.
// Handling insertions before deletions may result in unexpected behavior.
collectionView.deleteItems(at: deletions.map { IndexPath(item: $0, section: 0) })
Expand All @@ -392,6 +396,9 @@ class FileListViewController: UIViewController, UICollectionViewDataSource, Swip
for (source, target) in moved {
collectionView.moveItem(at: IndexPath(item: source, section: 0), to: IndexPath(item: target, section: 0))
}
SentryDebug.updateFileListBreadcrumb(id: reloadId, step: "performBatchUpdates end")
} completion: { _ in
SentryDebug.updateFileListBreadcrumb(id: reloadId, step: "performBatchUpdates completion")
}
// Reload corners (outside of batch to prevent incompatible operations)
reloadFileCorners(insertions: insertions, deletions: deletions)
Expand Down
2 changes: 2 additions & 0 deletions kDrive/UI/Controller/Files/File List/FileListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ class FileListViewModel: SelectDelegate {
switch change {
case .initial(let results):
files = AnyRealmCollection(results)
SentryDebug.filesObservationBreadcrumb(state: "initial")
onFileListUpdated?([], [], [], [], currentDirectory.fullyDownloaded && results.isEmpty, true)
case .update(let results, deletions: let deletions, insertions: let insertions, modifications: let modifications):
files = AnyRealmCollection(results)
SentryDebug.filesObservationBreadcrumb(state: "update")
onFileListUpdated?(
deletions,
insertions,
Expand Down
12 changes: 12 additions & 0 deletions kDriveCore/Utils/SentryDebug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ public enum SentryDebug {
SentrySDK.addBreadcrumb(breadcrumb)
}

public static func updateFileListBreadcrumb(id: String, step: String) {
let breadcrumb = Breadcrumb(level: .error, category: Category.uploadOperation)
breadcrumb.message = "updateFileList opId: \(id) step: \(step)"
SentrySDK.addBreadcrumb(breadcrumb)
}

public static func filesObservationBreadcrumb(state: String) {
let breadcrumb = Breadcrumb(level: .error, category: Category.uploadOperation)
breadcrumb.message = "files modified: \(state) "
SentrySDK.addBreadcrumb(breadcrumb)
}

// MARK: - Upload notifications

static func uploadNotificationError(_ metadata: [String: Any]) {
Expand Down

0 comments on commit 7ee60a1

Please sign in to comment.