diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-03-21 12:59:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-21 12:59:10 -0500 |
commit | 858d4c8c8811ca8e16bffe3bfe0d541e576177ec (patch) | |
tree | 8199e1029edb7161c34fb59806399c30fcdd61a3 /src/state/models/link-metas-view.ts | |
parent | c1d454b7cfe6a7ec107b39483df9cb0fb64e1c76 (diff) | |
download | voidsky-858d4c8c8811ca8e16bffe3bfe0d541e576177ec.tar.zst |
* Introduce an image sizes cache to improve feed layouts (close #213) * Clear out resolved promises from the image cache
Diffstat (limited to 'src/state/models/link-metas-view.ts')
-rw-r--r-- | src/state/models/link-metas-view.ts | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/src/state/models/link-metas-view.ts b/src/state/models/link-metas-view.ts deleted file mode 100644 index 59447008a..000000000 --- a/src/state/models/link-metas-view.ts +++ /dev/null @@ -1,44 +0,0 @@ -import {makeAutoObservable} from 'mobx' -import {LRUMap} from 'lru_map' -import {RootStoreModel} from './root-store' -import {LinkMeta, getLinkMeta} from 'lib/link-meta/link-meta' - -type CacheValue = Promise<LinkMeta> | LinkMeta -export class LinkMetasViewModel { - cache: LRUMap<string, CacheValue> = new LRUMap(100) - - constructor(public rootStore: RootStoreModel) { - makeAutoObservable( - this, - { - rootStore: false, - cache: false, - }, - {autoBind: true}, - ) - } - - // public api - // = - - async getLinkMeta(url: string) { - const cached = this.cache.get(url) - if (cached) { - try { - return await cached - } catch (e) { - // ignore, we'll try again - } - } - try { - const promise = getLinkMeta(this.rootStore, url) - this.cache.set(url, promise) - const res = await promise - this.cache.set(url, res) - return res - } catch (e) { - this.cache.delete(url) - throw e - } - } -} |