Use a post and handle-resolution cache to enable quick postthread loading (#1097)
* Use a post and handle-resolution cache to enable quick postthread loading * Fix positioning of thread when loaded from cache and give more visual cues * Include parent posts in cache * Include notifications in cache
This commit is contained in:
parent
7256169506
commit
a63f97aef2
9 changed files with 167 additions and 18 deletions
5
src/state/models/cache/handle-resolutions.ts
vendored
Normal file
5
src/state/models/cache/handle-resolutions.ts
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import {LRUMap} from 'lru_map'
|
||||
|
||||
export class HandleResolutionsCache {
|
||||
cache: LRUMap<string, string> = new LRUMap(500)
|
||||
}
|
||||
31
src/state/models/cache/posts.ts
vendored
Normal file
31
src/state/models/cache/posts.ts
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import {LRUMap} from 'lru_map'
|
||||
import {RootStoreModel} from '../root-store'
|
||||
import {AppBskyFeedDefs} from '@atproto/api'
|
||||
|
||||
type PostView = AppBskyFeedDefs.PostView
|
||||
|
||||
export class PostsCache {
|
||||
cache: LRUMap<string, PostView> = new LRUMap(500)
|
||||
|
||||
constructor(public rootStore: RootStoreModel) {}
|
||||
|
||||
set(uri: string, postView: PostView) {
|
||||
this.cache.set(uri, postView)
|
||||
if (postView.author.handle) {
|
||||
this.rootStore.handleResolutions.cache.set(
|
||||
postView.author.handle,
|
||||
postView.author.did,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fromFeedItem(feedItem: AppBskyFeedDefs.FeedViewPost) {
|
||||
this.set(feedItem.post.uri, feedItem.post)
|
||||
if (
|
||||
feedItem.reply?.parent &&
|
||||
AppBskyFeedDefs.isPostView(feedItem.reply?.parent)
|
||||
) {
|
||||
this.set(feedItem.reply.parent.uri, feedItem.reply.parent)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue