Skip to content

Commit

Permalink
refactor: Rollback old optimisation that was not the source of the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Dec 18, 2024
1 parent 5720aa7 commit 7b826b3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions kDriveCore/Data/Models/Drive/Drive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ public final class Drive: Object, Codable {
return []
}

// If File is not managed by Realm: cannot use the `.sorted(by:)` method :(
// Also the Realm sort can crash if managed by realm
let fileCategoriesIds = file.categories.sorted { $0.addedAt.compare($1.addedAt) == .orderedAscending }.map(\.categoryId)
let fileCategoriesIds: [Int]
if file.isManagedByRealm {
fileCategoriesIds = Array(file.categories.sorted(by: \.addedAt, ascending: true)).map(\.categoryId)
} else {
fileCategoriesIds = file.categories.sorted { $0.addedAt.compare($1.addedAt) == .orderedAscending }.map(\.categoryId)
}
let filteredCategories = categories.filter("id IN %@", fileCategoriesIds)

// Sort the categories
Expand Down

0 comments on commit 7b826b3

Please sign in to comment.