mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-01 09:50:16 +00:00
Add Dinosaurs window.
This commit is contained in:
1 parent
2cdd6d89ba
commit
eb5bfd6ca5
15 files changed
+459
-2
No files matched your search
@@ -884,6 +884,11 @@ public enum FetchType {
|
||||
try database.fetchAllArticlesCount(feedIDs: flattenedFeedsIDs)
|
||||
}
|
||||
|
||||
/// Returns a dictionary of feedID → latest article date for all feeds with articles.
|
||||
public func fetchLastUpdateDates() async throws -> [String: Date] {
|
||||
try await database.fetchLastUpdateDates()
|
||||
}
|
||||
|
||||
public func fetchUnreadCountForTodayAsync() async throws -> Int {
|
||||
try await database.fetchUnreadCountForTodayAsync(feedIDs: flattenedFeedsIDs)
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public extension Feed {
|
||||
case externalID
|
||||
case folderRelationship
|
||||
case lastCheckDate
|
||||
case lastResponseCode
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -189,6 +189,17 @@ import Articles
|
||||
settings.lastCheckDate = newValue
|
||||
}
|
||||
}
|
||||
|
||||
/// HTTP status code from the most recent feed download attempt.
|
||||
public var lastResponseCode: Int? {
|
||||
get {
|
||||
settings.lastResponseCode
|
||||
}
|
||||
set {
|
||||
settings.lastResponseCode = newValue
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - DisplayNameProvider
|
||||
|
||||
public var nameForDisplay: String {
|
||||
|
||||
@@ -149,6 +149,16 @@ import Articles
|
||||
}
|
||||
}
|
||||
|
||||
/// HTTP status code from the most recent feed download attempt.
|
||||
var lastResponseCode: Int? {
|
||||
didSet {
|
||||
if lastResponseCode != oldValue {
|
||||
database.setInt(lastResponseCode, for: feedURL, column: .lastResponseCode)
|
||||
postSettingDidChange(.lastResponseCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from database row (bulk load at startup).
|
||||
init(feedURL: String, row: FeedSettingsDatabase.Row, database: FeedSettingsDatabase) {
|
||||
self.feedURL = feedURL
|
||||
@@ -168,6 +178,7 @@ import Articles
|
||||
self.externalID = row.externalID
|
||||
self.folderRelationship = row.folderRelationship
|
||||
self.lastCheckDate = row.lastCheckDate
|
||||
self.lastResponseCode = row.lastResponseCode
|
||||
}
|
||||
|
||||
/// Create for a new feed not yet in the database.
|
||||
|
||||
@@ -31,6 +31,7 @@ final class FeedSettingsDatabase: Sendable {
|
||||
case externalID
|
||||
case folderRelationship
|
||||
case lastCheckDate
|
||||
case lastResponseCode
|
||||
}
|
||||
|
||||
struct Row {
|
||||
@@ -49,6 +50,7 @@ final class FeedSettingsDatabase: Sendable {
|
||||
let externalID: String?
|
||||
let folderRelationship: [String: String]?
|
||||
let lastCheckDate: Date?
|
||||
let lastResponseCode: Int?
|
||||
}
|
||||
|
||||
let databasePath: String
|
||||
@@ -63,6 +65,9 @@ final class FeedSettingsDatabase: Sendable {
|
||||
self.database = FMDatabase.openAndSetUpDatabase(path: databasePath)
|
||||
serialDispatchQueue.sync { [database] in
|
||||
database.runCreateStatements(Self.tableCreationStatements)
|
||||
if !database.columnExists("lastResponseCode", inTableWithName: "feedSettings") {
|
||||
database.executeStatements("ALTER TABLE feedSettings ADD COLUMN lastResponseCode INTEGER;")
|
||||
}
|
||||
}
|
||||
vacuumIfNeeded()
|
||||
}
|
||||
@@ -159,6 +164,19 @@ final class FeedSettingsDatabase: Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Int
|
||||
|
||||
func setInt(_ value: Int?, for feedURL: String, column: Column) {
|
||||
let name = column.rawValue
|
||||
serialDispatchQueue.async {
|
||||
if let value {
|
||||
self.database.executeUpdate("UPDATE feedSettings SET \(name) = ? WHERE feedURL = ?;", withArgumentsIn: [value, feedURL])
|
||||
} else {
|
||||
self.database.executeUpdate("UPDATE feedSettings SET \(name) = NULL WHERE feedURL = ?;", withArgumentsIn: [feedURL])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Date
|
||||
|
||||
func setDate(_ value: Date?, for feedURL: String, column: Column) {
|
||||
@@ -253,7 +271,7 @@ final class FeedSettingsDatabase: Sendable {
|
||||
private extension FeedSettingsDatabase {
|
||||
|
||||
static let tableCreationStatements = """
|
||||
CREATE TABLE IF NOT EXISTS feedSettings (feedURL TEXT PRIMARY KEY, feedID TEXT NOT NULL DEFAULT '', homePageURL TEXT, iconURL TEXT, faviconURL TEXT, editedName TEXT, contentHash TEXT, newArticleNotificationsEnabled INTEGER NOT NULL DEFAULT 0, readerViewAlwaysEnabled INTEGER NOT NULL DEFAULT 0, authors TEXT, conditionalGetInfoLastModified TEXT, conditionalGetInfoEtag TEXT, conditionalGetInfoDate REAL, cacheControlInfoDateCreated REAL, cacheControlInfoMaxAge REAL, externalID TEXT, folderRelationship TEXT, lastCheckDate REAL);
|
||||
CREATE TABLE IF NOT EXISTS feedSettings (feedURL TEXT PRIMARY KEY, feedID TEXT NOT NULL DEFAULT '', homePageURL TEXT, iconURL TEXT, faviconURL TEXT, editedName TEXT, contentHash TEXT, newArticleNotificationsEnabled INTEGER NOT NULL DEFAULT 0, readerViewAlwaysEnabled INTEGER NOT NULL DEFAULT 0, authors TEXT, conditionalGetInfoLastModified TEXT, conditionalGetInfoEtag TEXT, conditionalGetInfoDate REAL, cacheControlInfoDateCreated REAL, cacheControlInfoMaxAge REAL, externalID TEXT, folderRelationship TEXT, lastCheckDate REAL, lastResponseCode INTEGER);
|
||||
"""
|
||||
|
||||
func row(from resultSet: FMResultSet) -> Row {
|
||||
@@ -289,6 +307,11 @@ private extension FeedSettingsDatabase {
|
||||
lastCheckDate = Date(timeIntervalSinceReferenceDate: resultSet.double(forColumn: Column.lastCheckDate.rawValue))
|
||||
}
|
||||
|
||||
var lastResponseCode: Int?
|
||||
if !resultSet.columnIsNull(Column.lastResponseCode.rawValue) {
|
||||
lastResponseCode = Int(resultSet.int(forColumn: Column.lastResponseCode.rawValue))
|
||||
}
|
||||
|
||||
return Row(
|
||||
feedID: resultSet.swiftString(forColumn: Column.feedID.rawValue) ?? "",
|
||||
homePageURL: resultSet.swiftString(forColumn: Column.homePageURL.rawValue),
|
||||
@@ -304,7 +327,8 @@ private extension FeedSettingsDatabase {
|
||||
cacheControlInfo: cacheControlInfo,
|
||||
externalID: resultSet.swiftString(forColumn: Column.externalID.rawValue),
|
||||
folderRelationship: folderRelationship,
|
||||
lastCheckDate: lastCheckDate
|
||||
lastCheckDate: lastCheckDate,
|
||||
lastResponseCode: lastResponseCode
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -240,6 +240,8 @@ import os
|
||||
return
|
||||
}
|
||||
|
||||
feed.lastResponseCode = httpResponse.statusCode
|
||||
|
||||
let statusIsOK = httpResponse.statusIsOK
|
||||
let statusIsOKOrNotModified = statusIsOK || httpResponse.statusCode == HTTPResponseCode.notModified
|
||||
guard statusIsOKOrNotModified else {
|
||||
|
||||
@@ -151,6 +151,16 @@ public struct ArticleChanges: Sendable {
|
||||
return try articlesTable.fetchArticlesMatchingWithArticleIDs(searchString, articleIDs)
|
||||
}
|
||||
|
||||
/// Returns a dictionary of feedID → latest article date for all feeds with articles.
|
||||
public func fetchLastUpdateDates() async throws -> [String: Date] {
|
||||
Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)")
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
articlesTable.fetchLastUpdateDatesAsync { result in
|
||||
continuation.resume(with: result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Fetching Articles Async
|
||||
|
||||
public func fetchArticlesAsync(feedID: String) async throws -> Set<Article> {
|
||||
|
||||
@@ -112,6 +112,24 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
return try fetchArticlesCount { self.fetchAllArticlesCount(feedIDs, $0) }
|
||||
}
|
||||
|
||||
// MARK: - Fetching Last Update Dates
|
||||
|
||||
func fetchLastUpdateDatesAsync(_ completion: @escaping @Sendable (Result<[String: Date], DatabaseError>) -> Void) {
|
||||
queue.runInDatabase { databaseResult in
|
||||
switch databaseResult {
|
||||
case .success(let database):
|
||||
let result = self.fetchLastUpdateDates(database)
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(result))
|
||||
}
|
||||
case .failure(let databaseError):
|
||||
DispatchQueue.main.async {
|
||||
completion(.failure(databaseError))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Fetching Search Articles
|
||||
|
||||
func fetchArticlesMatching(_ searchString: String) throws -> Set<Article> {
|
||||
@@ -986,6 +1004,26 @@ nonisolated private extension ArticlesTable {
|
||||
return articles.filter { articleIDs.contains($0.articleID) }
|
||||
}
|
||||
|
||||
func fetchLastUpdateDates(_ database: FMDatabase) -> [String: Date] {
|
||||
guard let resultSet = database.executeQuery("SELECT feedID, MAX(coalesce(datePublished, dateModified)) as latestDate FROM articles GROUP BY feedID;", withArgumentsIn: []) else {
|
||||
return [:]
|
||||
}
|
||||
defer {
|
||||
resultSet.close()
|
||||
}
|
||||
|
||||
var result = [String: Date]()
|
||||
while resultSet.next() {
|
||||
guard let feedID = resultSet.string(forColumn: "feedID") else {
|
||||
continue
|
||||
}
|
||||
if !resultSet.columnIsNull("latestDate") {
|
||||
result[feedID] = resultSet.date(forColumn: "latestDate")
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// MARK: - Saving Parsed Items
|
||||
|
||||
func callUpdateArticlesCompletionBlock(_ newArticles: Set<Article>?, _ updatedArticles: Set<Article>?, _ deletedArticles: Set<Article>?, _ completion: @escaping UpdateArticlesCompletionBlock) {
|
||||
|
||||
Reference in new issue
Block a user