mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 17:23:37 +08:00
refactor(web): reuse resource key derivation (#17334)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user