Merge pull request #30859 from drodil/catalog_sorted
fix(catalog): processor order not to affect hash generation
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
---
|
||||
|
||||
Make the processing hash calculation not care about the order of the processors.
|
||||
|
||||
This change does not affect the behavior of the catalog, but it will make the processing
|
||||
hash calculation more robust against changes in the order of processors. This should lead to
|
||||
more stable processing hashes, which in turn should lead to fewer unnecessary reprocessing
|
||||
of entities.
|
||||
|
||||
After deploying this fix, you may see a period of increased processing and stitching, but
|
||||
this should stabilize over time as the processing hashes become more consistent.
|
||||
@@ -46,6 +46,11 @@ const tracer = trace.getTracer(TRACER_ID);
|
||||
|
||||
export type ProgressTracker = ReturnType<typeof progressTracker>;
|
||||
|
||||
const stableStringifyArray = (arr: any[]) => {
|
||||
const sorted = arr.map(stableStringify).sort();
|
||||
return `[${sorted.join(',')}]`;
|
||||
};
|
||||
|
||||
// NOTE(freben): Perhaps surprisingly, this class does not implement the
|
||||
// CatalogProcessingEngine type. That type is externally visible and its name is
|
||||
// the way it is for historic reasons. This class has no particular reason to
|
||||
@@ -226,10 +231,10 @@ export class DefaultCatalogProcessingEngine {
|
||||
|
||||
hashBuilder = hashBuilder
|
||||
.update(stableStringify({ ...result.completedEntity }))
|
||||
.update(stableStringify([...result.deferredEntities]))
|
||||
.update(stableStringify([...result.relations]))
|
||||
.update(stableStringify([...result.refreshKeys]))
|
||||
.update(stableStringify([...parents]));
|
||||
.update(stableStringifyArray([...result.deferredEntities]))
|
||||
.update(stableStringifyArray([...result.relations]))
|
||||
.update(stableStringifyArray([...result.refreshKeys]))
|
||||
.update(stableStringifyArray([...parents]));
|
||||
}
|
||||
|
||||
const resultHash = hashBuilder.digest('hex');
|
||||
|
||||
Reference in New Issue
Block a user