Skip to content

Commit

Permalink
Fix loading of open item from database
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed Oct 25, 2023
1 parent fb6ab8d commit 114f136
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
15 changes: 0 additions & 15 deletions Zotero/Controllers/Database/Requests/ReadItemDbRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,3 @@ struct ReadItemDbRequest: DbResponseRequest {
return item
}
}

struct ReadItemGloballyDbRequest: DbResponseRequest {
typealias Response = RItem

let key: String

var needsWrite: Bool { return false }

func process(in database: Realm) throws -> RItem {
guard let item = database.objects(RItem.self).filter(.key(key)).first else {
throw DbError.objectNotFound
}
return item
}
}
13 changes: 8 additions & 5 deletions Zotero/Controllers/OpenItemsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,14 @@ final class OpenItemsController {
do {
try dbStorage.perform(on: .main) { coordinator in
for item in items {
do {
let rItem = try coordinator.perform(request: ReadItemGloballyDbRequest(key: item.key))
itemTuples.append((item, rItem))
} catch let itemError {
DDLogError("OpenItemsController: can't load globally item \(item) - \(itemError)")
switch item {
case .pdf(let libraryId, let key):
do {
let rItem = try coordinator.perform(request: ReadItemDbRequest(libraryId: libraryId, key: key))
itemTuples.append((item, rItem))
} catch let itemError {
DDLogError("OpenItemsController: can't load item \(item) - \(itemError)")
}
}
}
}
Expand Down

0 comments on commit 114f136

Please sign in to comment.