mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-31 20:03:37 +00:00
perf(ui): smooth large lists and graphs
This commit is contained in:
@@ -7,6 +7,8 @@ export {
|
||||
resolveDependencies,
|
||||
areDependenciesSatisfied,
|
||||
getBlockingDependencies,
|
||||
createFeatureMap,
|
||||
getBlockingDependenciesFromMap,
|
||||
wouldCreateCircularDependency,
|
||||
dependencyExists,
|
||||
getAncestors,
|
||||
|
||||
@@ -229,6 +229,49 @@ export function getBlockingDependencies(feature: Feature, allFeatures: Feature[]
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a lookup map for features by id.
|
||||
*
|
||||
* @param features - Features to index
|
||||
* @returns Map keyed by feature id
|
||||
*/
|
||||
export function createFeatureMap(features: Feature[]): Map<string, Feature> {
|
||||
const featureMap = new Map<string, Feature>();
|
||||
for (const feature of features) {
|
||||
if (feature?.id) {
|
||||
featureMap.set(feature.id, feature);
|
||||
}
|
||||
}
|
||||
return featureMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the blocking dependencies using a precomputed feature map.
|
||||
*
|
||||
* @param feature - Feature to check
|
||||
* @param featureMap - Map of all features by id
|
||||
* @returns Array of feature IDs that are blocking this feature
|
||||
*/
|
||||
export function getBlockingDependenciesFromMap(
|
||||
feature: Feature,
|
||||
featureMap: Map<string, Feature>
|
||||
): string[] {
|
||||
const dependencies = feature.dependencies;
|
||||
if (!dependencies || dependencies.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const blockingDependencies: string[] = [];
|
||||
for (const depId of dependencies) {
|
||||
const dep = featureMap.get(depId);
|
||||
if (dep && dep.status !== 'completed' && dep.status !== 'verified') {
|
||||
blockingDependencies.push(depId);
|
||||
}
|
||||
}
|
||||
|
||||
return blockingDependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if adding a dependency from sourceId to targetId would create a circular dependency.
|
||||
* When we say "targetId depends on sourceId", we add sourceId to targetId.dependencies.
|
||||
|
||||
@@ -3,6 +3,8 @@ import {
|
||||
resolveDependencies,
|
||||
areDependenciesSatisfied,
|
||||
getBlockingDependencies,
|
||||
createFeatureMap,
|
||||
getBlockingDependenciesFromMap,
|
||||
wouldCreateCircularDependency,
|
||||
dependencyExists,
|
||||
} from '../src/resolver';
|
||||
@@ -351,6 +353,21 @@ describe('resolver.ts', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBlockingDependenciesFromMap', () => {
|
||||
it('should match getBlockingDependencies when using a feature map', () => {
|
||||
const dep1 = createFeature('Dep1', { status: 'pending' });
|
||||
const dep2 = createFeature('Dep2', { status: 'completed' });
|
||||
const dep3 = createFeature('Dep3', { status: 'running' });
|
||||
const feature = createFeature('A', { dependencies: ['Dep1', 'Dep2', 'Dep3'] });
|
||||
const allFeatures = [dep1, dep2, dep3, feature];
|
||||
const featureMap = createFeatureMap(allFeatures);
|
||||
|
||||
expect(getBlockingDependenciesFromMap(feature, featureMap)).toEqual(
|
||||
getBlockingDependencies(feature, allFeatures)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('wouldCreateCircularDependency', () => {
|
||||
it('should return false for features with no existing dependencies', () => {
|
||||
const features = [createFeature('A'), createFeature('B')];
|
||||
|
||||
Reference in New Issue
Block a user