Fetch all accounts much less often
This commit is contained in:
parent
f1391cecce
commit
fee51ace09
@ -115,7 +115,7 @@ extension HomeTimelineViewModel.LoadLatestState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
await AuthenticationServiceProvider.shared.fetchAccounts()
|
await AuthenticationServiceProvider.shared.fetchAccounts(onlyIfItHasBeenAwhile: true)
|
||||||
let response: Mastodon.Response.Content<[Mastodon.Entity.Status]>
|
let response: Mastodon.Response.Content<[Mastodon.Entity.Status]>
|
||||||
|
|
||||||
/// To find out wether or not we need to show the "Load More" button
|
/// To find out wether or not we need to show the "Load More" button
|
||||||
|
@ -61,7 +61,7 @@ extension HomeTimelineViewModel.LoadOldestState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
await AuthenticationServiceProvider.shared.fetchAccounts()
|
await AuthenticationServiceProvider.shared.fetchAccounts(onlyIfItHasBeenAwhile: true)
|
||||||
|
|
||||||
let response: Mastodon.Response.Content<[Mastodon.Entity.Status]>
|
let response: Mastodon.Response.Content<[Mastodon.Entity.Status]>
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ extension HomeTimelineViewModel {
|
|||||||
guard let status = record.status else { return }
|
guard let status = record.status else { return }
|
||||||
record.isLoadingMore = true
|
record.isLoadingMore = true
|
||||||
|
|
||||||
await AuthenticationServiceProvider.shared.fetchAccounts()
|
await AuthenticationServiceProvider.shared.fetchAccounts(onlyIfItHasBeenAwhile: true)
|
||||||
|
|
||||||
// fetch data
|
// fetch data
|
||||||
let response: Mastodon.Response.Content<[Mastodon.Entity.Status]>?
|
let response: Mastodon.Response.Content<[Mastodon.Entity.Status]>?
|
||||||
|
@ -10,6 +10,9 @@ import os.log
|
|||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
public class AuthenticationServiceProvider: ObservableObject {
|
public class AuthenticationServiceProvider: ObservableObject {
|
||||||
|
|
||||||
|
private(set) var lastFetchOfAllAccounts: Date?
|
||||||
|
|
||||||
private let logger = Logger(subsystem: "AuthenticationServiceProvider", category: "Authentication")
|
private let logger = Logger(subsystem: "AuthenticationServiceProvider", category: "Authentication")
|
||||||
|
|
||||||
public static let shared = AuthenticationServiceProvider()
|
public static let shared = AuthenticationServiceProvider()
|
||||||
@ -238,11 +241,25 @@ public extension AuthenticationServiceProvider {
|
|||||||
userDefaults.didMigrateAuthentications == false
|
userDefaults.didMigrateAuthentications == false
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchAccounts() async {
|
func fetchAccounts(onlyIfItHasBeenAwhile: Bool) async {
|
||||||
// FIXME: This is a dirty hack to make the performance-stuff work.
|
// FIXME: This is a dirty hack to make the performance-stuff work.
|
||||||
// Problem is, that we don't persist the user on disk anymore. So we have to fetch
|
// Problem is, that we don't persist the user on disk anymore. So we have to fetch
|
||||||
// it when we need it to display on the home timeline.
|
// it when we need it to display on the home timeline.
|
||||||
// We need this (also) for the Account-list, but it might be the wrong place. App Startup might be more appropriate
|
// We need this (also) for the Account-list, but it might be the wrong place. App Startup might be more appropriate
|
||||||
|
|
||||||
|
let minTimeBetweenAutomaticAccountFetches = TimeInterval( 60 * 60 * 24) // one day
|
||||||
|
let itHasBeenAwhile: Bool
|
||||||
|
|
||||||
|
if let lastFetch = lastFetchOfAllAccounts {
|
||||||
|
itHasBeenAwhile = lastFetch.distance(to: Date.now) > minTimeBetweenAutomaticAccountFetches
|
||||||
|
} else {
|
||||||
|
itHasBeenAwhile = true
|
||||||
|
}
|
||||||
|
|
||||||
|
guard itHasBeenAwhile else { return }
|
||||||
|
|
||||||
|
lastFetchOfAllAccounts = Date.now
|
||||||
|
|
||||||
for authentication in authentications {
|
for authentication in authentications {
|
||||||
guard let account = try? await APIService.shared.accountInfo(MastodonAuthenticationBox(authentication: authentication)) else { continue }
|
guard let account = try? await APIService.shared.accountInfo(MastodonAuthenticationBox(authentication: authentication)) else { continue }
|
||||||
}
|
}
|
||||||
|
@ -205,10 +205,11 @@ final public class FeedDataController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private extension FeedDataController {
|
private extension FeedDataController {
|
||||||
|
|
||||||
func load(kind: MastodonFeed.Kind, maxID: MastodonStatus.ID?) async throws -> [MastodonFeed] {
|
func load(kind: MastodonFeed.Kind, maxID: MastodonStatus.ID?) async throws -> [MastodonFeed] {
|
||||||
switch kind {
|
switch kind {
|
||||||
case .home(let timeline):
|
case .home(let timeline):
|
||||||
await AuthenticationServiceProvider.shared.fetchAccounts()
|
await AuthenticationServiceProvider.shared.fetchAccounts(onlyIfItHasBeenAwhile: true)
|
||||||
|
|
||||||
let response: Mastodon.Response.Content<[Mastodon.Entity.Status]>
|
let response: Mastodon.Response.Content<[Mastodon.Entity.Status]>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user