From 9c3070d5fece7abf3a1a3c8f586028618efc78f3 Mon Sep 17 00:00:00 2001 From: Adam Abeshouse Date: Thu, 7 Oct 2021 10:37:23 -0400 Subject: [PATCH] comparison page: fetch all samples and then filter them down, cache optimization Signed-off-by: Adam Abeshouse --- .../groupComparison/GroupComparisonStore.ts | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/pages/groupComparison/GroupComparisonStore.ts b/src/pages/groupComparison/GroupComparisonStore.ts index 9cfc4613db4..792d950bd38 100644 --- a/src/pages/groupComparison/GroupComparisonStore.ts +++ b/src/pages/groupComparison/GroupComparisonStore.ts @@ -27,6 +27,7 @@ import { SessionGroupData, VirtualStudy, } from 'shared/api/session-service/sessionServiceModels'; +import ComplexKeySet from 'shared/lib/complexKeyDataStructures/ComplexKeySet'; export default class GroupComparisonStore extends ComparisonStore { @observable.ref private sessionId: string; @@ -276,24 +277,38 @@ export default class GroupComparisonStore extends ComparisonStore { } private readonly _samples = remoteData({ await: () => [this._session], - invoke: () => { - const sampleIdentifiers = []; + invoke: async () => { + const allStudies = _.flatMapDeep( + this._session.result!.groups, + groupData => groupData.studies.map(s => s.id) + ); + + // fetch all samples - faster backend processing time + const allSamples = await client.fetchSamplesUsingPOST({ + sampleFilter: { + sampleListIds: allStudies.map(studyId => `${studyId}_all`), + } as SampleFilter, + projection: 'DETAILED', + }); + + // filter to get samples in our groups + const sampleSet = new ComplexKeySet(); for (const groupData of this._session.result!.groups) { for (const studySpec of groupData.studies) { const studyId = studySpec.id; for (const sampleId of studySpec.samples) { - sampleIdentifiers.push({ + sampleSet.add({ studyId, sampleId, }); } } } - return client.fetchSamplesUsingPOST({ - sampleFilter: { - sampleIdentifiers, - } as SampleFilter, - projection: 'DETAILED', + return allSamples.filter(sample => { + return sampleSet.has({ + studyId: sample.studyId, + sampleId: sample.sampleId, + }); }); }, });