fix(lib/assets/caches): fix cached check logic
This commit is contained in:
parent
3947b8f07e
commit
f2badf63f9
2 changed files with 8 additions and 12 deletions
|
|
@ -19,12 +19,15 @@ const CacheStorage = getStorage<Cache>(`revenge/assets.${Key}`, {
|
|||
|
||||
// TODO(lib/assets/caches): This loads way too late and requires native interop to load earlier
|
||||
// biome-ignore lint/complexity/useArrowFunction: Arrow functions are not supported
|
||||
export const promise = CacheStorage.get().then(async function (cache_) {
|
||||
export const cached = CacheStorage.get().then(async function (cache_) {
|
||||
const cached = cache_ !== cache
|
||||
// If we are not using the default value, merge it into the in-memory cache, then point the storage cache to the in-memory cache.
|
||||
if (cache_ !== cache) {
|
||||
if (cached) {
|
||||
Object.assign(cache, cache_)
|
||||
CacheStorage.cache = cache
|
||||
}
|
||||
|
||||
return cached
|
||||
})
|
||||
|
||||
export interface Cache {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { byName, byProps } from '@revenge-mod/modules/finders/filters'
|
|||
import { waitForModules } from '@revenge-mod/modules/finders/wait'
|
||||
import { getModuleDependencies } from '@revenge-mod/modules/metro/utils'
|
||||
import { _overrides } from './_internal'
|
||||
import { cache, cacheAsset, promise } from './caches'
|
||||
import { cacheAsset, cached } from './caches'
|
||||
import type { ReactNative } from '@revenge-mod/react/types'
|
||||
import type { Asset, PackagerAsset } from './types'
|
||||
|
||||
|
|
@ -26,15 +26,8 @@ const unsubAR = waitForModules(
|
|||
unsubAR()
|
||||
|
||||
// TODO(lib/assets/caches): Ideally we should not wait for the cache promise here, see the promise impl for more info.
|
||||
promise.then(() => {
|
||||
// Make sure we don't try to recache assets if it is already cached.
|
||||
let uncached = true
|
||||
for (const _ in cache) {
|
||||
uncached = false
|
||||
break
|
||||
}
|
||||
|
||||
if (uncached) {
|
||||
cached.then(cached => {
|
||||
if (!cached) {
|
||||
// More fragile way, but also more performant:
|
||||
// There is exactly one asset before the reexported asset registry :/
|
||||
const firstAssetModuleId = id - 1
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue