From 21deedc7b42cc0070d974d10414fbaa7e77a2a72 Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Mon, 15 Apr 2024 13:58:19 +0300 Subject: [PATCH] Improve OpenItemsController items observer registration --- Zotero/Controllers/OpenItemsController.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Zotero/Controllers/OpenItemsController.swift b/Zotero/Controllers/OpenItemsController.swift index 231042bee..6dc61e8fc 100644 --- a/Zotero/Controllers/OpenItemsController.swift +++ b/Zotero/Controllers/OpenItemsController.swift @@ -177,6 +177,7 @@ final class OpenItemsController { var existingItems = getItems(for: sessionIdentifier) if let index = existingItems.firstIndex(where: { $0.kind == kind }) { existingItems[index].lastOpened = .now + // No need to call setItems, to register a new items observer, as only items metadata were updated. itemsBySessionIdentifier[sessionIdentifier] = existingItems DDLogInfo("OpenItemsController: already opened item \(kind) became most recent for \(sessionIdentifier)") observable(for: sessionIdentifier).on(.next(existingItems)) @@ -204,7 +205,8 @@ final class OpenItemsController { var itemsChanged: Bool = false defer { if itemsChanged { - observable(for: sessionIdentifier).on(.next(existingItems)) + // setItems will produce next observable event + setItems(existingItems, for: sessionIdentifier, validate: false) } } var item: Item?