diff options
Diffstat (limited to 'src/state')
-rw-r--r-- | src/state/models/cache/profiles-view.ts | 4 | ||||
-rw-r--r-- | src/state/models/content/profile.ts | 26 |
2 files changed, 25 insertions, 5 deletions
diff --git a/src/state/models/cache/profiles-view.ts b/src/state/models/cache/profiles-view.ts index b4bd70db5..e5a9be587 100644 --- a/src/state/models/cache/profiles-view.ts +++ b/src/state/models/cache/profiles-view.ts @@ -45,8 +45,6 @@ export class ProfilesCache { } overwrite(did: string, res: GetProfile.Response) { - if (this.cache.has(did)) { - this.cache.set(did, res) - } + this.cache.set(did, res) } } diff --git a/src/state/models/content/profile.ts b/src/state/models/content/profile.ts index c4cbe6d44..2ea4ada6e 100644 --- a/src/state/models/content/profile.ts +++ b/src/state/models/content/profile.ts @@ -103,7 +103,12 @@ export class ProfileModel { // = async setup() { - await this._load() + const precache = await this.rootStore.profiles.cache.get(this.params.actor) + if (precache) { + await this._loadWithCache(precache) + } else { + await this._load() + } } async refresh() { @@ -252,7 +257,7 @@ export class ProfileModel { this._xLoading(isRefreshing) try { const res = await this.rootStore.agent.getProfile(this.params) - this.rootStore.profiles.overwrite(this.params.actor, res) // cache invalidation + this.rootStore.profiles.overwrite(this.params.actor, res) if (res.data.handle) { this.rootStore.handleResolutions.cache.set( res.data.handle, @@ -267,6 +272,23 @@ export class ProfileModel { } } + async _loadWithCache(precache: GetProfile.Response) { + // use cached value + this._replaceAll(precache) + await this._createRichText() + this._xIdle() + + // fetch latest + try { + const res = await this.rootStore.agent.getProfile(this.params) + this.rootStore.profiles.overwrite(this.params.actor, res) // cache invalidation + this._replaceAll(res) + await this._createRichText() + } catch (e: any) { + this._xIdle(e) + } + } + _replaceAll(res: GetProfile.Response) { this.did = res.data.did this.handle = res.data.handle |