fix(lib/assets/caches): fix cached check logic

This commit is contained in:
PalmDevs 2025-06-08 22:07:40 +07:00
parent 3947b8f07e
commit f2badf63f9
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
2 changed files with 8 additions and 12 deletions

View file

@ -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 {

View file

@ -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