From 9317874478230cbfecf605bfd597011776fc3a06 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 10 Jun 2024 22:47:22 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20performance=20issue=20on=20launch=20?= =?UTF-8?q?=E2=80=94=C2=A0ignore=20structure=20changes=20while=20loading?= =?UTF-8?q?=20from=20OPML=20until=20after=20loading.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Account/Sources/Account/Account.swift | 18 ++++++++++++++++-- Account/Sources/Account/OPMLFile.swift | 12 +++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index 28a8e67f7..337af16ec 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -331,7 +331,11 @@ public enum FetchType { metadataFile.load() feedMetadataFile.load() - opmlFile.load() + BatchUpdate.shared.perform { + if let opmlItems = opmlFile.opmlItems() { + loadOPMLItems(opmlItems) + } + } Task { @MainActor in try? await self.database.cleanupDatabaseAtStartup(subscribedToFeedIDs: self.flattenedFeeds().feedIDs()) @@ -752,6 +756,10 @@ public enum FetchType { // Feeds were added or deleted. Or folders added or deleted. // Or feeds inside folders were added or deleted. + guard !BatchUpdate.shared.isPerforming else { + return + } + logger.info("structureDidChange in account \(self.accountID)") Task { @MainActor in @@ -911,7 +919,9 @@ public enum FetchType { public func addFeed(_ feed: Feed) { topLevelFeeds.insert(feed) structureDidChange() - postChildrenDidChangeNotification() + if !BatchUpdate.shared.isPerforming { + postChildrenDidChangeNotification() + } } func addFeedIfNotInAnyFolder(_ feed: Feed) { @@ -972,6 +982,10 @@ public enum FetchType { } @MainActor @objc func childrenDidChange(_ note: Notification) { + + guard !BatchUpdate.shared.isPerforming else { + return + } guard let object = note.object else { return } diff --git a/Account/Sources/Account/OPMLFile.swift b/Account/Sources/Account/OPMLFile.swift index 6622449ff..eb3d0cb13 100644 --- a/Account/Sources/Account/OPMLFile.swift +++ b/Account/Sources/Account/OPMLFile.swift @@ -35,14 +35,12 @@ import Core dataFile.markAsDirty() } - func load() { - guard let fileData = opmlFileData(), let opmlItems = parsedOPMLItems(fileData: fileData) else { - return - } - - BatchUpdate.shared.perform { - account.loadOPMLItems(opmlItems) + func opmlItems() -> [RSOPMLItem]? { + guard let fileData = opmlFileData() else { + return nil } + + return parsedOPMLItems(fileData: fileData) } func save() {