From 5d98fdf66ea047eec42804abe9b015fed76fa71c Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 6 Dec 2026 10:29:44 +0800 Subject: [PATCH] refactor(web): reuse resource key derivation (#17334) --- src/domain/webInventory.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/domain/webInventory.ts b/src/domain/webInventory.ts index cf9b24ba75..c28cca8d5a 100644 --- a/src/domain/webInventory.ts +++ b/src/domain/webInventory.ts @@ -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)