mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 14:54:31 +00:00
refactor(core): dedupe final pairing and sandbox media clones
This commit is contained in:
@@ -30,6 +30,7 @@ type AllowFromReadCacheEntry = {
|
||||
size: number | null;
|
||||
entries: string[];
|
||||
};
|
||||
type AllowFromStatLike = { mtimeMs: number; size: number } | null;
|
||||
|
||||
const allowFromReadCache = new Map<string, AllowFromReadCacheEntry>();
|
||||
|
||||
@@ -321,6 +322,31 @@ function resolveAllowFromReadCacheHit(params: {
|
||||
return cloneAllowFromCacheEntry(cached);
|
||||
}
|
||||
|
||||
function resolveAllowFromReadCacheOrMissing(
|
||||
filePath: string,
|
||||
stat: AllowFromStatLike,
|
||||
): { entries: string[]; exists: boolean } | null {
|
||||
const cached = resolveAllowFromReadCacheHit({
|
||||
filePath,
|
||||
exists: Boolean(stat),
|
||||
mtimeMs: stat?.mtimeMs ?? null,
|
||||
size: stat?.size ?? null,
|
||||
});
|
||||
if (cached) {
|
||||
return { entries: cached.entries, exists: cached.exists };
|
||||
}
|
||||
if (!stat) {
|
||||
setAllowFromReadCache(filePath, {
|
||||
exists: false,
|
||||
mtimeMs: null,
|
||||
size: null,
|
||||
entries: [],
|
||||
});
|
||||
return { entries: [], exists: false };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function readAllowFromStateForPathWithExists(
|
||||
channel: PairingChannel,
|
||||
filePath: string,
|
||||
@@ -335,24 +361,9 @@ async function readAllowFromStateForPathWithExists(
|
||||
}
|
||||
}
|
||||
|
||||
const cached = resolveAllowFromReadCacheHit({
|
||||
filePath,
|
||||
exists: Boolean(stat),
|
||||
mtimeMs: stat?.mtimeMs ?? null,
|
||||
size: stat?.size ?? null,
|
||||
});
|
||||
if (cached) {
|
||||
return { entries: cached.entries, exists: cached.exists };
|
||||
}
|
||||
|
||||
if (!stat) {
|
||||
setAllowFromReadCache(filePath, {
|
||||
exists: false,
|
||||
mtimeMs: null,
|
||||
size: null,
|
||||
entries: [],
|
||||
});
|
||||
return { entries: [], exists: false };
|
||||
const cachedOrMissing = resolveAllowFromReadCacheOrMissing(filePath, stat);
|
||||
if (cachedOrMissing) {
|
||||
return cachedOrMissing;
|
||||
}
|
||||
|
||||
const { value, exists } = await readJsonFile<AllowFromStore>(filePath, {
|
||||
@@ -387,24 +398,9 @@ function readAllowFromStateForPathSyncWithExists(
|
||||
}
|
||||
}
|
||||
|
||||
const cached = resolveAllowFromReadCacheHit({
|
||||
filePath,
|
||||
exists: Boolean(stat),
|
||||
mtimeMs: stat?.mtimeMs ?? null,
|
||||
size: stat?.size ?? null,
|
||||
});
|
||||
if (cached) {
|
||||
return { entries: cached.entries, exists: cached.exists };
|
||||
}
|
||||
|
||||
if (!stat) {
|
||||
setAllowFromReadCache(filePath, {
|
||||
exists: false,
|
||||
mtimeMs: null,
|
||||
size: null,
|
||||
entries: [],
|
||||
});
|
||||
return { entries: [], exists: false };
|
||||
const cachedOrMissing = resolveAllowFromReadCacheOrMissing(filePath, stat);
|
||||
if (cachedOrMissing) {
|
||||
return cachedOrMissing;
|
||||
}
|
||||
|
||||
let raw = "";
|
||||
|
||||
Reference in New Issue
Block a user