Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MergeDataSource): remove duplicated instances and fix to issue #4349 #4355

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions extensions/default/src/MergeDataSource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export const mergeMap: MergeMap = {
return series;
},
},
'getStudyInstanceUIDs': {
mergeKey: 'studyInstanceUid',
tagFunc: x => x,
},
};

/**
Expand Down Expand Up @@ -92,12 +96,15 @@ export const callForAllDataSourcesAsync = async ({
* @returns The merged data from all the matching data sources.
*/
export const callForAllDataSources = ({
mergeMap,
path,
args,
extensionManager,
dataSourceNames,
defaultDataSourceName,
}: CallForAllDataSourcesOptions) => {
const { mergeKey, tagFunc } = mergeMap[path] || { tagFunc: x => x };

/** Sort by default data source */
const defs = Object.values(extensionManager.dataSourceDefs);
const defaultDataSourceDef = defs.find(def => def.sourceName === defaultDataSourceName);
Expand All @@ -106,18 +113,30 @@ export const callForAllDataSources = ({
dataSourceDefs.unshift(defaultDataSourceDef);
}

const mergedData = [];
const dataArray = [];
const sourceNames = [];

for (const dataSourceDef of dataSourceDefs) {
const { configuration, sourceName } = dataSourceDef;
if (!!configuration && dataSourceNames.includes(sourceName)) {
const [dataSource] = extensionManager.getDataSources(sourceName);
const func = get(dataSource, path);
const data = func.apply(dataSource, args);
mergedData.push(data);
dataArray.push(data);
sourceNames.push(sourceName);
}
}

return mergedData.flat();
const mergedData = dataArray.map((data, i) => tagFunc(data, sourceNames[i]));

let results = [];
if (mergeKey) {
results = uniqBy(mergedData.flat(), obj => get(obj, mergeKey, obj));
} else {
results = mergedData.flat();
}

return results;
};

/**
Expand Down Expand Up @@ -176,6 +195,7 @@ function createMergeDataSourceApi(
const implementation = {
initialize: (...args: unknown[]) =>
callForAllDataSources({
mergeMap,
path: 'initialize',
args,
extensionManager,
Expand Down Expand Up @@ -257,6 +277,7 @@ function createMergeDataSourceApi(
},
deleteStudyMetadataPromise: (...args: unknown[]) =>
callForAllDataSources({
mergeMap,
path: 'deleteStudyMetadataPromise',
args,
extensionManager,
Expand All @@ -279,6 +300,7 @@ function createMergeDataSourceApi(
}),
getStudyInstanceUIDs: (...args: unknown[]) =>
callForAllDataSources({
mergeMap,
path: 'getStudyInstanceUIDs',
args,
extensionManager,
Expand Down
1 change: 1 addition & 0 deletions extensions/default/src/MergeDataSource/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type CallForAllDataSourcesAsyncOptions = {
};

export type CallForAllDataSourcesOptions = {
mergeMap: object;
path: string;
args: unknown[];
dataSourceNames: string[];
Expand Down
6 changes: 3 additions & 3 deletions platform/app/src/routes/Mode/defaultRouteInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export async function defaultRouteInit(
const remainingPromises = [];

function startRemainingPromises(remainingPromises) {
remainingPromises.forEach(p => p.forEach(p => p.start()));
remainingPromises.forEach(p => p.forEach(p => p));
}

promises.forEach(promise => {
Expand All @@ -130,15 +130,15 @@ export async function defaultRouteInit(

if (displaySetFromUrl) {
const requiredSeriesPromises = retrieveSeriesMetadataPromise.map(promise =>
promise.start()
promise
);
allPromises.push(Promise.allSettled(requiredSeriesPromises));
} else {
const { requiredSeries, remaining } = hangingProtocolService.filterSeriesRequiredForRun(
hangingProtocolId,
retrieveSeriesMetadataPromise
);
const requiredSeriesPromises = requiredSeries.map(promise => promise.start());
const requiredSeriesPromises = requiredSeries.map(promise => promise);
allPromises.push(Promise.allSettled(requiredSeriesPromises));
remainingPromises.push(remaining);
}
Expand Down
Loading