mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-02-17 02:05:13 +00:00
Make loading account data faster
This commit is contained in:
parent
d447a8fdd2
commit
a77ee6b7af
1 changed files with 34 additions and 14 deletions
|
@ -100,23 +100,26 @@ class AccountDetailViewModel: ObservableObject, StatusesFetcher {
|
||||||
self.accountState = .data(account: account)
|
self.accountState = .data(account: account)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct AccountData {
|
||||||
|
let account: Account
|
||||||
|
let featuredTags: [FeaturedTag]
|
||||||
|
let relationships: [Relationshionship]
|
||||||
|
let familliarFollowers: [FamilliarAccounts]
|
||||||
|
}
|
||||||
|
|
||||||
func fetchAccount() async {
|
func fetchAccount() async {
|
||||||
guard let client else { return }
|
guard let client else { return }
|
||||||
do {
|
do {
|
||||||
async let account: Account = client.get(endpoint: Accounts.accounts(id: accountId))
|
let data = try await fetchAccountData(accountId: accountId, client: client)
|
||||||
async let featuredTags: [FeaturedTag] = client.get(endpoint: Accounts.featuredTags(id: accountId))
|
accountState = .data(account: data.account)
|
||||||
let loadedAccount = try await account
|
|
||||||
self.account = loadedAccount
|
account = data.account
|
||||||
self.featuredTags = try await featuredTags
|
fields = data.account.fields
|
||||||
self.featuredTags.sort { $0.statusesCountInt > $1.statusesCountInt }
|
featuredTags = data.featuredTags
|
||||||
self.fields = loadedAccount.fields
|
featuredTags.sort { $0.statusesCountInt > $1.statusesCountInt }
|
||||||
if client.isAuth {
|
relationship = data.relationships.first
|
||||||
async let relationships: [Relationshionship] = client.get(endpoint: Accounts.relationships(ids: [accountId]))
|
familliarFollowers = data.familliarFollowers.first?.accounts ?? []
|
||||||
async let familliarFollowers: [FamilliarAccounts] = client.get(endpoint: Accounts.familiarFollowers(withAccount: accountId))
|
|
||||||
self.relationship = try await relationships.first
|
|
||||||
self.familliarFollowers = try await familliarFollowers.first?.accounts ?? []
|
|
||||||
}
|
|
||||||
accountState = .data(account: loadedAccount)
|
|
||||||
} catch {
|
} catch {
|
||||||
if let account {
|
if let account {
|
||||||
accountState = .data(account: account)
|
accountState = .data(account: account)
|
||||||
|
@ -126,6 +129,23 @@ class AccountDetailViewModel: ObservableObject, StatusesFetcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchAccountData(accountId: String, client: Client) async throws -> AccountData {
|
||||||
|
async let account: Account = client.get(endpoint: Accounts.accounts(id: accountId))
|
||||||
|
async let featuredTags: [FeaturedTag] = client.get(endpoint: Accounts.featuredTags(id: accountId))
|
||||||
|
if client.isAuth && !isCurrentUser {
|
||||||
|
async let relationships: [Relationshionship] = client.get(endpoint: Accounts.relationships(ids: [accountId]))
|
||||||
|
async let familliarFollowers: [FamilliarAccounts] = client.get(endpoint: Accounts.familiarFollowers(withAccount: accountId))
|
||||||
|
return try await .init(account: account,
|
||||||
|
featuredTags: featuredTags,
|
||||||
|
relationships: relationships,
|
||||||
|
familliarFollowers: familliarFollowers)
|
||||||
|
}
|
||||||
|
return try await .init(account: account,
|
||||||
|
featuredTags: featuredTags,
|
||||||
|
relationships: [],
|
||||||
|
familliarFollowers: [])
|
||||||
|
}
|
||||||
|
|
||||||
func fetchStatuses() async {
|
func fetchStatuses() async {
|
||||||
guard let client else { return }
|
guard let client else { return }
|
||||||
do {
|
do {
|
||||||
|
|
Loading…
Reference in a new issue