Don't process OPML file if it hasn't changed since it was last produced. Issue #1428
This commit is contained in:
parent
358f386c4b
commit
b8ef6c7549
|
@ -1161,10 +1161,10 @@ extension Account: OPMLRepresentable {
|
||||||
|
|
||||||
public func OPMLString(indentLevel: Int, strictConformance: Bool) -> String {
|
public func OPMLString(indentLevel: Int, strictConformance: Bool) -> String {
|
||||||
var s = ""
|
var s = ""
|
||||||
for feed in topLevelWebFeeds {
|
for feed in topLevelWebFeeds.sorted(by: { $0.nameForDisplay < $1.nameForDisplay }) {
|
||||||
s += feed.OPMLString(indentLevel: indentLevel + 1, strictConformance: strictConformance)
|
s += feed.OPMLString(indentLevel: indentLevel + 1, strictConformance: strictConformance)
|
||||||
}
|
}
|
||||||
for folder in folders! {
|
for folder in folders!.sorted(by: { $0.nameForDisplay < $1.nameForDisplay }) {
|
||||||
s += folder.OPMLString(indentLevel: indentLevel + 1, strictConformance: strictConformance)
|
s += folder.OPMLString(indentLevel: indentLevel + 1, strictConformance: strictConformance)
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
|
|
|
@ -189,7 +189,7 @@ extension Folder: OPMLRepresentable {
|
||||||
|
|
||||||
var hasAtLeastOneChild = false
|
var hasAtLeastOneChild = false
|
||||||
|
|
||||||
for feed in topLevelWebFeeds {
|
for feed in topLevelWebFeeds.sorted(by: { $0.nameForDisplay < $1.nameForDisplay }) {
|
||||||
s += feed.OPMLString(indentLevel: indentLevel + 1, strictConformance: strictConformance)
|
s += feed.OPMLString(indentLevel: indentLevel + 1, strictConformance: strictConformance)
|
||||||
hasAtLeastOneChild = true
|
hasAtLeastOneChild = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,17 @@ final class OPMLFile {
|
||||||
private extension OPMLFile {
|
private extension OPMLFile {
|
||||||
|
|
||||||
func loadCallback() {
|
func loadCallback() {
|
||||||
guard let opmlItems = parsedOPMLItems() else { return }
|
guard let fileData = opmlFileData() else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't rebuild the account if the OPML hasn't changed since the last save
|
||||||
|
guard let opml = String(data: fileData, encoding: .utf8), opml != opmlDocument() else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let opmlItems = parsedOPMLItems(fileData: fileData) else { return }
|
||||||
|
|
||||||
BatchUpdate.shared.perform {
|
BatchUpdate.shared.perform {
|
||||||
account.topLevelWebFeeds.removeAll()
|
account.topLevelWebFeeds.removeAll()
|
||||||
account.loadOPMLItems(opmlItems, parentFolder: nil)
|
account.loadOPMLItems(opmlItems, parentFolder: nil)
|
||||||
|
@ -77,8 +87,7 @@ private extension OPMLFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parsedOPMLItems() -> [RSOPMLItem]? {
|
func opmlFileData() -> Data? {
|
||||||
|
|
||||||
var fileData: Data? = nil
|
var fileData: Data? = nil
|
||||||
let errorPointer: NSErrorPointer = nil
|
let errorPointer: NSErrorPointer = nil
|
||||||
let fileCoordinator = NSFileCoordinator(filePresenter: managedFile)
|
let fileCoordinator = NSFileCoordinator(filePresenter: managedFile)
|
||||||
|
@ -98,11 +107,11 @@ private extension OPMLFile {
|
||||||
os_log(.error, log: log, "OPML read from disk coordination failed: %@.", error.localizedDescription)
|
os_log(.error, log: log, "OPML read from disk coordination failed: %@.", error.localizedDescription)
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let opmlData = fileData else {
|
return fileData
|
||||||
return nil
|
}
|
||||||
}
|
|
||||||
|
func parsedOPMLItems(fileData: Data) -> [RSOPMLItem]? {
|
||||||
let parserData = ParserData(url: fileURL.absoluteString, data: opmlData)
|
let parserData = ParserData(url: fileURL.absoluteString, data: fileData)
|
||||||
var opmlDocument: RSOPMLDocument?
|
var opmlDocument: RSOPMLDocument?
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -113,7 +122,6 @@ private extension OPMLFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
return opmlDocument?.children
|
return opmlDocument?.children
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func opmlDocument() -> String {
|
func opmlDocument() -> String {
|
||||||
|
|
Loading…
Reference in New Issue