Fix performance issue on launch — ignore structure changes while loading from OPML until after loading.

This commit is contained in:
Brent Simmons 2024-06-10 22:47:22 -07:00
parent 7fe5f94262
commit 9317874478
2 changed files with 21 additions and 9 deletions

View File

@ -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
}

View File

@ -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() {