summaryrefslogtreecommitdiff
path: root/Sora/Data
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-23 22:02:59 -0800
committerFuwn <[email protected]>2026-02-23 22:02:59 -0800
commit7904b2366a28fca2585b5f5ec0588412e10f0c94 (patch)
treee57236200c0f377d0d06f1c90231551f7be3dbed /Sora/Data
parentfeat: localize accessibility fallback and value strings (diff)
downloadsora-testing-main.tar.xz
sora-testing-main.zip
perf: cache danbooru page token floor and reuse search-history payloadsHEADmain
Diffstat (limited to 'Sora/Data')
-rw-r--r--Sora/Data/Booru/BooruManager.swift10
-rw-r--r--Sora/Data/Settings/SettingsManager.swift20
2 files changed, 21 insertions, 9 deletions
diff --git a/Sora/Data/Booru/BooruManager.swift b/Sora/Data/Booru/BooruManager.swift
index 3c4374e..2957fcd 100644
--- a/Sora/Data/Booru/BooruManager.swift
+++ b/Sora/Data/Booru/BooruManager.swift
@@ -30,6 +30,7 @@ class BooruManager: ObservableObject { // swiftlint:disable:this type_body_leng
private let showHeldMoebooruPosts: Bool
private var urlCache: [String: URL] = [:]
private var lastPostCount = 0
+ private var cachedMinimumPostID: Int?
// MARK: - Computed Properties
var tags: [String] {
@@ -340,9 +341,7 @@ class BooruManager: ObservableObject { // swiftlint:disable:this type_body_leng
guard page > 1 else { return "1" }
guard !hasExplicitSortTag(in: tags) else { return String(page) }
- guard let minimumPostID = posts.lazy.compactMap({ Int($0.id) }).min() else {
- return String(page)
- }
+ guard let minimumPostID = cachedMinimumPostID else { return String(page) }
return "b\(minimumPostID)"
}
@@ -545,12 +544,17 @@ class BooruManager: ObservableObject { // swiftlint:disable:this type_body_leng
postIndexMap.removeAll()
lastPostCount = 0
+ cachedMinimumPostID = nil
}
endOfData = newPosts.isEmpty
guard !endOfData else { return }
+ if let nextMinimumPostID = newPosts.lazy.compactMap({ Int($0.id) }).min() {
+ cachedMinimumPostID = min(cachedMinimumPostID ?? nextMinimumPostID, nextMinimumPostID)
+ }
+
withTransaction(Transaction(animation: nil)) {
let oldCount = self.posts.count
diff --git a/Sora/Data/Settings/SettingsManager.swift b/Sora/Data/Settings/SettingsManager.swift
index b07b38c..78aef7c 100644
--- a/Sora/Data/Settings/SettingsManager.swift
+++ b/Sora/Data/Settings/SettingsManager.swift
@@ -198,13 +198,17 @@ class SettingsManager: ObservableObject { // swiftlint:disable:this type_body_l
defer { isUpdatingCache = false }
+ let sortedSearchHistory = newValue.sorted { $0.date > $1.date }
+ let payload = SettingsCodec.encodeOnce(sortedSearchHistory)
+
syncableData(
key: "searchHistory",
localData: $searchHistoryData,
- newValue: newValue,
- ) { $0.sorted { $0.date > $1.date } }
+ newValue: sortedSearchHistory,
+ encodedData: payload?.encodedData
+ ) { $0 }
- searchHistoryCache = newValue.sorted { $0.date > $1.date }
+ searchHistoryCache = sortedSearchHistory
pendingSyncKeys.insert(.searchHistory)
triggerBatchedSync()
@@ -427,13 +431,17 @@ class SettingsManager: ObservableObject { // swiftlint:disable:this type_body_l
defer { isUpdatingCache = false }
+ let sortedSearchHistory = newValue.sorted { $0.date > $1.date }
+ let payload = SettingsCodec.encodeOnce(sortedSearchHistory)
+
syncableData(
key: "searchHistory",
localData: $searchHistoryData,
- newValue: newValue,
- ) { $0.sorted { $0.date > $1.date } }
+ newValue: sortedSearchHistory,
+ encodedData: payload?.encodedData
+ ) { $0 }
- searchHistoryCache = newValue.sorted { $0.date > $1.date }
+ searchHistoryCache = sortedSearchHistory
pendingSyncKeys.insert(.searchHistory)
triggerBatchedSync()