Remove old migration path
This migration path was in the last release v1.6.63, and it has now been out there for a couple of months so apart from some outliers the migration should've already happened. Even for the outliers, this will increase their cache size but won't have a functional impact. Cleaning this code now to reduce the amount that needs to be changed to support a contextBridge aware cache.
This commit is contained in:
parent
0eedd5e57f
commit
467acf2b8e
|
@ -1,6 +1,5 @@
|
|||
import crypto from "crypto";
|
||||
import path from "path";
|
||||
import { existsSync, rename, stat, unlink } from "promise-fs";
|
||||
import { existsSync, stat, unlink } from "promise-fs";
|
||||
import DiskLRUService from "../services/diskLRU";
|
||||
import { LimitedCache } from "../types/cache";
|
||||
import { getFileStream, writeStream } from "./fs";
|
||||
|
@ -44,28 +43,6 @@ export class DiskCache implements LimitedCache {
|
|||
DiskLRUService.touch(cachePath);
|
||||
return new Response(await getFileStream(cachePath));
|
||||
} else {
|
||||
// add fallback for old cache keys
|
||||
const oldCachePath = getOldAssetCachePath(
|
||||
this.cacheBucketDir,
|
||||
cacheKey,
|
||||
);
|
||||
if (existsSync(oldCachePath)) {
|
||||
const fileStats = await stat(oldCachePath);
|
||||
if (sizeInBytes && fileStats.size !== sizeInBytes) {
|
||||
logError(
|
||||
Error(),
|
||||
"Old cache key exists but size does not match. Deleting cache key.",
|
||||
);
|
||||
unlink(oldCachePath).catch((e) => {
|
||||
if (e.code === "ENOENT") return;
|
||||
logError(e, "Failed to delete cache key");
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
const match = new Response(await getFileStream(oldCachePath));
|
||||
void migrateOldCacheKey(oldCachePath, cachePath);
|
||||
return match;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
@ -79,20 +56,3 @@ export class DiskCache implements LimitedCache {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getOldAssetCachePath(cacheDir: string, cacheKey: string) {
|
||||
// hashing the key to prevent illegal filenames
|
||||
const cacheKeyHash = crypto
|
||||
.createHash("sha256")
|
||||
.update(cacheKey)
|
||||
.digest("hex");
|
||||
return path.join(cacheDir, cacheKeyHash);
|
||||
}
|
||||
|
||||
async function migrateOldCacheKey(oldCacheKey: string, newCacheKey: string) {
|
||||
try {
|
||||
await rename(oldCacheKey, newCacheKey);
|
||||
} catch (e) {
|
||||
logError(e, "Failed to move cache key to new cache key");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue