refactor(web): reuse resource key derivation (#17334)

This commit is contained in:
Vincent Koc
2026-12-06 10:29:44 +08:00
committed by GitHub
parent 7d4dcedfe2
commit 5d98fdf66e
+7 -9
View File
@@ -46,19 +46,19 @@ export const webResourceComparisonIdentity = (
"Web resource comparison identity",
)}`;
const resourceKey = (resource: WebInventoryResourceInput): string =>
`res_${digestCanonicalValue(resource, "Web inventory")}`;
/** Assign deterministic identities to a bounded resource inventory. */
export const stableWebResources = (
resources: readonly WebInventoryResourceInput[],
): StableWebResource[] => {
const keyed = resources.map((resource) => ({
...resource,
resource_key: `res_${digestCanonicalValue(resource, "Web inventory")}`,
resource_key: resourceKey(resource),
}));
return [
...new Map(
keyed.map((resource) => [resource.resource_key, resource]),
).values(),
].sort(
const byKey = new Map(keyed.map((row) => [row.resource_key, row]));
return [...byKey.values()].sort(
(left, right) =>
compareUnicodeCodePoints(left.resource_key, right.resource_key) ||
compareUnicodeCodePoints(left.url, right.url),
@@ -93,9 +93,7 @@ export const createCapturedWebScriptReconciler = (
const resource = rawByUrl.get(script.rawUrl);
if (resource !== undefined && resource !== null) {
const { rawUrl: _rawUrl, ...publicResource } = resource;
const stable = stableWebResources([publicResource])[0];
if (stable !== undefined)
return { status: "exact", resource_key: stable.resource_key };
return { status: "exact", resource_key: resourceKey(publicResource) };
}
const candidates = keysByUrl.get(script.url);
if (candidates !== undefined)