mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-05 03:37:41 +00:00
Use approachable concurrency with FeedFinder.
This commit is contained in:
1 parent
83df10d8cf
commit
644690696f
4 files changed
+15
-12
No files matched your search
@@ -24,6 +24,9 @@ let package = Package(
|
||||
"RSCore"
|
||||
],
|
||||
swiftSettings: [
|
||||
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances"),
|
||||
.defaultIsolation(MainActor.self),
|
||||
.unsafeFlags(["-warnings-as-errors"])
|
||||
]
|
||||
),
|
||||
|
||||
@@ -23,11 +23,11 @@ public enum FeedFinderError: LocalizedError {
|
||||
}
|
||||
}
|
||||
|
||||
public final class FeedFinder {
|
||||
nonisolated public final class FeedFinder {
|
||||
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "FeedFinder")
|
||||
|
||||
public static func find(url: URL) async throws -> Set<FeedSpecifier> {
|
||||
@concurrent public static func find(url: URL) async throws -> Set<FeedSpecifier> {
|
||||
// Check special cases first.
|
||||
if let feedSpecifier = FeedSpecifier.knownFeedSpecifier(url: url) {
|
||||
logger.info("FeedFinder: found special case feed URL: \(url.absoluteString) - \(feedSpecifier.urlString)")
|
||||
@@ -68,10 +68,10 @@ public final class FeedFinder {
|
||||
}
|
||||
}
|
||||
|
||||
private extension FeedFinder {
|
||||
|
||||
nonisolated private extension FeedFinder {
|
||||
|
||||
static func addFeedSpecifier(_ feedSpecifier: FeedSpecifier, feedSpecifiers: inout [String: FeedSpecifier]) {
|
||||
// If there’s an existing feed specifier, merge the two so that we have the best data. If one has a title and one doesn’t, use that non-nil title. Use the better source.
|
||||
// If there's an existing feed specifier, merge the two so that we have the best data. If one has a title and one doesn't, use that non-nil title. Use the better source.
|
||||
|
||||
if let existingFeedSpecifier = feedSpecifiers[feedSpecifier.urlString] {
|
||||
let mergedFeedSpecifier = existingFeedSpecifier.feedSpecifierByMerging(feedSpecifier)
|
||||
@@ -122,8 +122,8 @@ private extension FeedFinder {
|
||||
var feedSpecifiers = HTMLFeedFinder(parserData: parserData).feedSpecifiers
|
||||
|
||||
if feedSpecifiers.isEmpty {
|
||||
// Odds are decent it’s a WordPress site, and just adding /feed/ will work.
|
||||
// It’s also fairly common for /index.xml to work.
|
||||
// Odds are decent it's a WordPress site, and just adding /feed/ will work.
|
||||
// It's also fairly common for /index.xml to work.
|
||||
if let url = URL(string: urlString) {
|
||||
let feedURL = url.appendingPathComponent("feed", isDirectory: true)
|
||||
let wordpressFeedSpecifier = FeedSpecifier(title: nil, urlString: feedURL.absoluteString, source: .HTMLLink, orderFound: 1)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
import RSWeb
|
||||
|
||||
public struct FeedSpecifier: Hashable, Sendable {
|
||||
nonisolated public struct FeedSpecifier: Hashable, Sendable {
|
||||
|
||||
public enum Source: Int, Sendable {
|
||||
case UserEntered = 0, HTMLHead, HTMLLink
|
||||
@@ -77,7 +77,7 @@ public struct FeedSpecifier: Hashable, Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
private extension FeedSpecifier {
|
||||
nonisolated private extension FeedSpecifier {
|
||||
|
||||
func calculatedScore() -> Int {
|
||||
var score = 0
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
import Foundation
|
||||
import RSParser
|
||||
|
||||
private let feedURLWordsToMatch = ["feed", "xml", "rss", "atom", "json"]
|
||||
nonisolated private let feedURLWordsToMatch = ["feed", "xml", "rss", "atom", "json"]
|
||||
|
||||
final class HTMLFeedFinder {
|
||||
nonisolated final class HTMLFeedFinder {
|
||||
|
||||
var feedSpecifiers: Set<FeedSpecifier> {
|
||||
return Set(feedSpecifiersDictionary.values)
|
||||
@@ -42,7 +42,7 @@ final class HTMLFeedFinder {
|
||||
}
|
||||
}
|
||||
|
||||
private extension HTMLFeedFinder {
|
||||
nonisolated private extension HTMLFeedFinder {
|
||||
|
||||
func addFeedSpecifier(_ feedSpecifier: FeedSpecifier) {
|
||||
// If there’s an existing feed specifier, merge the two so that we have the best data. If one has a title and one doesn’t, use that non-nil title. Use the better source.
|
||||
|
||||
Reference in new issue
Block a user