Change parseDatePublished() to a lazy var parsedDatePublished — it appeared that it was getting called more than once, and date parsing is expensive. Also: use RSDateWithString rather than an NSDateFormatter, since NSDateFormatter is so massively slow.

This commit is contained in:
Brent Simmons 2019-09-27 23:01:31 -07:00
parent 07a631309c
commit d7b45a1413
2 changed files with 15 additions and 15 deletions

View File

@ -1109,7 +1109,7 @@ private extension FeedbinAccountDelegate {
let parsedItems: [ParsedItem] = entries.map { entry in
let authors = Set([ParsedAuthor(name: entry.authorName, url: entry.jsonFeed?.jsonFeedAuthor?.url, avatarURL: entry.jsonFeed?.jsonFeedAuthor?.avatarURL, emailAddress: nil)])
return ParsedItem(syncServiceID: String(entry.articleID), uniqueID: String(entry.articleID), feedURL: String(entry.feedID), url: nil, externalURL: entry.url, title: entry.title, contentHTML: entry.contentHTML, contentText: nil, summary: entry.summary, imageURL: nil, bannerImageURL: nil, datePublished: entry.parseDatePublished(), dateModified: nil, authors: authors, tags: nil, attachments: nil)
return ParsedItem(syncServiceID: String(entry.articleID), uniqueID: String(entry.articleID), feedURL: String(entry.feedID), url: nil, externalURL: entry.url, title: entry.title, contentHTML: entry.contentHTML, contentText: nil, summary: entry.summary, imageURL: nil, bannerImageURL: nil, datePublished: entry.parsedDatePublished, dateModified: nil, authors: authors, tags: nil, attachments: nil)
}
return Set(parsedItems)

View File

@ -10,7 +10,7 @@ import Foundation
import RSParser
import RSCore
struct FeedbinEntry: Codable {
final class FeedbinEntry: Codable {
let articleID: Int
let feedID: Int
@ -23,6 +23,19 @@ struct FeedbinEntry: Codable {
let dateArrived: String?
let jsonFeed: FeedbinEntryJSONFeed?
// Feedbin dates can't be decoded by the JSONDecoding 8601 decoding strategy. Feedbin
// requires a very specific date formatter to work and even then it fails occasionally.
// Rather than loose all the entries we only lose the one date by decoding as a string
// and letting the one date fail when parsed.
lazy var parsedDatePublished: Date? = {
if let datePublished = datePublished {
return RSDateWithString(datePublished)
}
else {
return nil
}
}()
enum CodingKeys: String, CodingKey {
case articleID = "id"
case feedID = "feed_id"
@ -35,19 +48,6 @@ struct FeedbinEntry: Codable {
case dateArrived = "created_at"
case jsonFeed = "json_feed"
}
// Feedbin dates can't be decoded by the JSONDecoding 8601 decoding strategy. Feedbin
// requires a very specific date formatter to work and even then it fails occasionally.
// Rather than loose all the entries we only lose the one date by decoding as a string
// and letting the one date fail when parsed.
func parseDatePublished() -> Date? {
if datePublished != nil {
return FeedbinDate.formatter.date(from: datePublished!)
} else {
return nil
}
}
}
struct FeedbinEntryJSONFeed: Codable {