Skip to content

Commit 1375162

Browse files
authored
Enh 1056 improve performance of extractor pipeline query (#1066)
* feat: added caching to query dependant on studies in project * feat: added loader to the table cells for AI columns instead of entire table * feat: added loader status for participant data in focus mode * maint: change file name * feat: changed GET to POST for extracted data requests
1 parent dadc7f8 commit 1375162

14 files changed

+164
-322
lines changed

compose/neurosynth-frontend/cypress/e2e/workflows/Curation/CurationAIInterface.cy.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ describe('CurationAIInterface', () => {
1818
{}
1919
).as('updateProject');
2020

21-
cy.intercept('GET', `**/api/pipeline-study-results/?feature_display=TaskExtractor*`, {
21+
cy.intercept('POST', `**/api/pipeline-study-results/?feature_display=TaskExtractor*`, {
2222
fixture: 'pipeline-results/TaskExtraction',
2323
}).as('participantDemographicsExtraction');
2424

25-
cy.intercept('GET', `**/api/pipeline-study-results/?feature_display=ParticipantDemographicsExtractor*`, {
25+
cy.intercept('POST', `**/api/pipeline-study-results/?feature_display=ParticipantDemographicsExtractor*`, {
2626
fixture: 'pipeline-results/ParticipantDemographicsExtraction',
2727
}).as('taskExtraction');
2828

compose/neurosynth-frontend/cypress/e2e/workflows/SleuthImport/DoSleuthImport.cy.tsx

Lines changed: 86 additions & 172 deletions
Large diffs are not rendered by default.

compose/neurosynth-frontend/src/hooks/extractions/useGetAllExtractedData.tsx renamed to compose/neurosynth-frontend/src/hooks/extractions/useGetAllExtractedDataForStudies.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,28 @@ export interface IExtractedDataResult {
102102
}[];
103103
}
104104

105-
const useGetAllAIExtractedData = () => {
105+
const useGetAllAIExtractedDataForStudies = (baseStudyIds?: string[]) => {
106+
const baseStudyIdsOrEmpty = baseStudyIds ?? [];
106107
return useQuery<
107108
[AxiosResponse<IExtractedDataResult>, AxiosResponse<IExtractedDataResult>],
108109
AxiosError,
109110
{
110111
[EAIExtractors.TASKEXTRACTOR]: IExtractedDataResult;
111112
[EAIExtractors.PARTICIPANTSDEMOGRAPHICSEXTRACTOR]: IExtractedDataResult;
112113
},
113-
[string]
114+
string[]
114115
>(
115-
['extraction'],
116+
['extraction', ...baseStudyIdsOrEmpty],
116117
async () => {
117118
const promises = await Promise.all([
118-
API.NeurostoreServices.ExtractedDataResultsService.getAllExtractedDataResults([
119-
EAIExtractors.TASKEXTRACTOR,
120-
]),
121-
API.NeurostoreServices.ExtractedDataResultsService.getAllExtractedDataResults([
122-
EAIExtractors.PARTICIPANTSDEMOGRAPHICSEXTRACTOR,
123-
]),
119+
API.NeurostoreServices.ExtractedDataResultsService.getAllExtractedDataResults(
120+
[EAIExtractors.TASKEXTRACTOR],
121+
baseStudyIdsOrEmpty
122+
),
123+
API.NeurostoreServices.ExtractedDataResultsService.getAllExtractedDataResults(
124+
[EAIExtractors.PARTICIPANTSDEMOGRAPHICSEXTRACTOR],
125+
baseStudyIdsOrEmpty
126+
),
124127
]);
125128

126129
promises.forEach((res) => {
@@ -136,8 +139,10 @@ const useGetAllAIExtractedData = () => {
136139
[EAIExtractors.PARTICIPANTSDEMOGRAPHICSEXTRACTOR]: participantDemographicsExtractionRes.data,
137140
};
138141
},
142+
refetchOnMount: false,
143+
enabled: baseStudyIdsOrEmpty.length > 0,
139144
}
140145
);
141146
};
142147

143-
export default useGetAllAIExtractedData;
148+
export default useGetAllAIExtractedDataForStudies;

compose/neurosynth-frontend/src/hooks/useGetExtractionSummary.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { EExtractionStatus } from 'pages/Extraction/ExtractionPage';
2-
import {
3-
useProjectExtractionStudysetId,
4-
useProjectExtractionStudyStatusList,
5-
} from 'pages/Project/store/ProjectStore';
2+
import { useProjectExtractionStudysetId, useProjectExtractionStudyStatusList } from 'pages/Project/store/ProjectStore';
63
import { useEffect, useState } from 'react';
74
import { IStudyExtractionStatus } from './projects/useGetProjects';
85
import useGetStudysetById from './studysets/useGetStudysetById';
@@ -14,10 +11,7 @@ export interface IExtractionSummary {
1411
total: number;
1512
}
1613

17-
export const getExtractionSummary = (
18-
studysetStudiesArg: Array<string>,
19-
studyStatusList: IStudyExtractionStatus[]
20-
) => {
14+
export const getExtractionSummary = (studysetStudiesArg: Array<string>, studyStatusList: IStudyExtractionStatus[]) => {
2115
const studysetStudies = studysetStudiesArg || [];
2216

2317
const summary = {

compose/neurosynth-frontend/src/pages/Curation/components/CurationBoardAIInterfaceCurator.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { GridTableRowsIcon } from '@mui/x-data-grid';
44
import { Row, Table } from '@tanstack/react-table';
55
import CurationPromoteUncategorizedButton from 'components/Buttons/CurationPromoteUncategorizedButton';
66
import { useUserCanEdit } from 'hooks';
7-
import useGetAllAIExtractedData from 'hooks/extractions/useGetAllExtractedData';
87
import { indexToPRISMAMapping } from 'hooks/projects/useGetProjects';
98
import {
109
useProjectCurationColumns,
@@ -18,7 +17,6 @@ import useCuratorTableState from '../hooks/useCuratorTableState';
1817
import { ICurationTableStudy } from '../hooks/useCuratorTableState.types';
1918
import { IGroupListItem } from './CurationBoardAIGroupsList';
2019
import CurationBoardAIInterfaceCuratorFocus from './CurationBoardAIInterfaceCuratorFocus';
21-
import CurationBoardAIInterfaceCuratorTableSkeleton from './CurationBoardAIInterfaceCuratorSkeleton';
2220
import CurationBoardAIInterfaceCuratorTable from './CurationBoardAIInterfaceCuratorTable';
2321
import CurationDownloadSummaryButton from './CurationDownloadSummaryButton';
2422
import PrismaDialog from './PrismaDialog';
@@ -38,7 +36,6 @@ const CurationBoardAIInterfaceCurator: React.FC<{
3836
const navigate = useNavigate();
3937
const { projectId } = useParams<{ projectId: string | undefined }>();
4038
const curationColumns = useProjectCurationColumns();
41-
const { isLoading } = useGetAllAIExtractedData();
4239

4340
const { column, columnIndex } = useMemo(() => {
4441
const columnIndex = curationColumns.findIndex((col) => col.id === group.id);
@@ -61,7 +58,7 @@ const CurationBoardAIInterfaceCurator: React.FC<{
6158
return column.stubStudies.filter((x) => x.exclusionTag === null);
6259
}, [column]);
6360

64-
const table = useCuratorTableState(projectId, stubsInColumn, !isLastColumn, prismaPhase !== 'identification');
61+
const { table } = useCuratorTableState(projectId, stubsInColumn, !isLastColumn, prismaPhase !== 'identification');
6562

6663
const [prismaIsOpen, setPrismaIsOpen] = useState(false);
6764
const [UIMode, setUIMode] = useState<'TABLEMODE' | 'FOCUSMODE'>('TABLEMODE');
@@ -71,9 +68,10 @@ const CurationBoardAIInterfaceCurator: React.FC<{
7168

7269
const [selectedStubId, setSelectedStubId] = useState<string>();
7370

71+
const rows = table.getCoreRowModel().rows;
7472
const selectedStub: Row<ICurationTableStudy> | undefined = useMemo(
75-
() => (table.getCoreRowModel().rows || []).find((stub) => stub.original.id === selectedStubId),
76-
[table, selectedStubId]
73+
() => (rows || []).find((stub) => stub.original.id === selectedStubId),
74+
[rows, selectedStubId]
7775
);
7876

7977
const handleToggleUIMode = () => {
@@ -116,10 +114,6 @@ const CurationBoardAIInterfaceCurator: React.FC<{
116114
return <Typography color="error.dark">There was an error loading studies</Typography>;
117115
}
118116

119-
if (isLoading) {
120-
return <CurationBoardAIInterfaceCuratorTableSkeleton />;
121-
}
122-
123117
return (
124118
<Box sx={{ height: '100%' }}>
125119
<Box

compose/neurosynth-frontend/src/pages/Curation/components/CurationBoardAIInterfaceCuratorSkeleton.tsx

Lines changed: 0 additions & 101 deletions
This file was deleted.

compose/neurosynth-frontend/src/pages/Curation/components/CurationBoardAIInterfaceCuratorTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Box, Chip, Table, TableCell, TableContainer, TableHead, TableRow, Typography } from '@mui/material';
22
import { flexRender, RowData } from '@tanstack/react-table';
33
import { useGetCurationSummary } from 'hooks';
4-
import { EAIExtractors } from 'hooks/extractions/useGetAllExtractedData';
4+
import { EAIExtractors } from 'hooks/extractions/useGetAllExtractedDataForStudies';
55
import { indexToPRISMAMapping } from 'hooks/projects/useGetProjects';
66
import { useProjectCurationPrismaConfig } from 'pages/Project/store/ProjectStore';
77
import { useRef } from 'react';

compose/neurosynth-frontend/src/pages/Curation/components/CurationBoardAIInterfaceCuratorTableCell.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Typography } from '@mui/material';
1+
import { Skeleton, Typography } from '@mui/material';
22
import { Box } from '@mui/system';
33
import { CellContext } from '@tanstack/react-table';
44
import React from 'react';
5+
import { useIsFetching } from 'react-query';
56
import {
67
ICurationTableColumnType,
78
ICurationTableStudy,
@@ -11,8 +12,14 @@ import {
1112
const CuratorTableCell: React.FC<Partial<CellContext<ICurationTableStudy, ICurationTableColumnType | null>>> = (
1213
props
1314
) => {
15+
const isFetchingExtractions = useIsFetching({ queryKey: ['extraction'] }) > 0;
16+
const isAI = !!props?.column?.columnDef?.meta?.AIExtractor;
1417
const cellValue = props.getValue ? props.getValue() : undefined;
1518

19+
if (isFetchingExtractions && isAI) {
20+
return <Skeleton width="100%" height="40px" />;
21+
}
22+
1623
if (cellValue === null) {
1724
// if there is no extraction done for the given study, we get null. This is in contrast
1825
// to studies that have an extraction, but some of the extracted values are null.

compose/neurosynth-frontend/src/pages/Curation/components/CurationStubAITableSummary.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AccordionDetails,
55
AccordionSummary,
66
Box,
7+
Skeleton,
78
Table,
89
TableBody,
910
TableCell,
@@ -12,16 +13,18 @@ import {
1213
Typography,
1314
} from '@mui/material';
1415
import AIICon from 'components/AIIcon';
15-
import { IfMRITask, IGroup } from 'hooks/extractions/useGetAllExtractedData';
16+
import { IfMRITask, IGroup } from 'hooks/extractions/useGetAllExtractedDataForStudies';
1617
import { useState } from 'react';
1718
import { useParams } from 'react-router-dom';
1819
import {
1920
PARTICIPANTS_DEMOGRAPHICS_EXTRACTOR_CURATOR_COLUMNS,
2021
TASK_EXTRACTOR_CURATOR_COLUMNS,
2122
} from '../hooks/useCuratorTableState.consts';
2223
import { ICurationTableStudy } from '../hooks/useCuratorTableState.types';
24+
import { useIsFetching } from 'react-query';
2325

2426
const CurationStubAITableSummary: React.FC<{ stub: ICurationTableStudy | undefined }> = ({ stub }) => {
27+
const isFetchingExtractions = useIsFetching({ queryKey: ['extraction'] }) > 0;
2528
const TaskExtractor = stub?.TaskExtractor;
2629
const { projectId } = useParams<{ projectId: string }>();
2730
const AIFocusModeSummaryLocalStorageKey = `${projectId}_FOCUS_MODE_AI_SUMMARY_EXPANDED_STATE`;
@@ -43,6 +46,15 @@ const CurationStubAITableSummary: React.FC<{ stub: ICurationTableStudy | undefin
4346
setExpandedState(newExpandedState);
4447
};
4548

49+
if (isFetchingExtractions) {
50+
return (
51+
<>
52+
<Skeleton width="100%" height="50px" sx={{ transform: 'none', marginBottom: '2px' }} />
53+
<Skeleton width="100%" height="50px" sx={{ transform: 'none' }} />
54+
</>
55+
);
56+
}
57+
4658
if (!TaskExtractor && !ParticipantDemographicsExtractor) {
4759
return (
4860
<Typography color="warning.dark" variant="body2">

compose/neurosynth-frontend/src/pages/Curation/hooks/useCuratorTableState.consts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EAIExtractors, IBehavioralTask, IfMRITask, IGroup } from 'hooks/extractions/useGetAllExtractedData';
1+
import { EAIExtractors, IBehavioralTask, IfMRITask, IGroup } from 'hooks/extractions/useGetAllExtractedDataForStudies';
22
import {
33
ICurationBoardAIInterfaceCuratorColumnType,
44
ICurationTableStudy,

0 commit comments

Comments
 (0)