mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-14 09:13:25 +01:00
Caches Friend Zone patrons to offset slow loading time
The Patreon API doesn’t have a way to fetch just the patrons belonging to our Friend Zone tier. Instead, we need to fetch ALL patrons (including inactive ones) and filter out those not in the tier. This is very inefficient, and takes over a minute to complete as of April 14, 2022, due to the number of patrons we have. We can’t do much to change this, but AltStore will now at least cache the fetched patrons with Core Data. Additionally, AltStore will only perform this long fetch whenever the Friend Zone list actually changes, rather than every time the Patreon screen appears.
This commit is contained in:
@@ -20,7 +20,8 @@ import Roxas
|
||||
|
||||
extension AppManager
|
||||
{
|
||||
static let didFetchSourceNotification = Notification.Name("com.altstore.AppManager.didFetchSource")
|
||||
static let didFetchSourceNotification = Notification.Name("io.altstore.AppManager.didFetchSource")
|
||||
static let didUpdatePatronsNotification = Notification.Name("io.altstore.AppManager.didUpdatePatrons")
|
||||
|
||||
static let expirationWarningNotificationID = "altstore-expiration-warning"
|
||||
static let enableJITResultNotificationID = "altstore-enable-jit"
|
||||
@@ -48,6 +49,8 @@ class AppManager
|
||||
@available(iOS 13, *)
|
||||
private(set) lazy var publisher: AppManagerPublisher = AppManagerPublisher()
|
||||
|
||||
private(set) var updatePatronsResult: Result<Void, Error>?
|
||||
|
||||
private let operationQueue = OperationQueue()
|
||||
private let serialOperationQueue = OperationQueue()
|
||||
|
||||
@@ -412,6 +415,34 @@ extension AppManager
|
||||
return fetchTrustedSourcesOperation
|
||||
}
|
||||
|
||||
func updatePatronsIfNeeded()
|
||||
{
|
||||
guard self.operationQueue.operations.allSatisfy({ !($0 is UpdatePatronsOperation) }) else {
|
||||
// There's already an UpdatePatronsOperation running.
|
||||
return
|
||||
}
|
||||
|
||||
self.updatePatronsResult = nil
|
||||
|
||||
let updatePatronsOperation = UpdatePatronsOperation()
|
||||
updatePatronsOperation.resultHandler = { (result) in
|
||||
do
|
||||
{
|
||||
try result.get()
|
||||
self.updatePatronsResult = .success(())
|
||||
}
|
||||
catch
|
||||
{
|
||||
print("Error updating Friend Zone Patrons:", error)
|
||||
self.updatePatronsResult = .failure(error)
|
||||
}
|
||||
|
||||
NotificationCenter.default.post(name: AppManager.didUpdatePatronsNotification, object: self)
|
||||
}
|
||||
|
||||
self.run([updatePatronsOperation], context: nil)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func install<T: AppProtocol>(_ app: T, presentingViewController: UIViewController?, context: AuthenticatedOperationContext = AuthenticatedOperationContext(), completionHandler: @escaping (Result<InstalledApp, Error>) -> Void) -> RefreshGroup
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user