Refactor: 쿼리 데이터 저장

This commit is contained in:
정현조 2024-09-25 08:43:53 +09:00
parent fbf4c7a6a5
commit 56f63f59f2

View File

@ -9,20 +9,32 @@ interface TrainingGraphProps {
}
export default function TrainingGraph({ projectId, selectedModel }: TrainingGraphProps) {
const { isTrainingByProject, setIsTraining, resetTrainingData } = useModelStore((state) => ({
isTrainingByProject: state.isTrainingByProject,
setIsTraining: state.setIsTraining,
resetTrainingData: state.resetTrainingData,
}));
const { isTrainingByProject, setIsTraining, saveTrainingData, resetTrainingData, trainingDataByProject } =
useModelStore((state) => ({
isTrainingByProject: state.isTrainingByProject,
setIsTraining: state.setIsTraining,
saveTrainingData: state.saveTrainingData,
resetTrainingData: state.resetTrainingData,
trainingDataByProject: state.trainingDataByProject,
}));
const isTraining = isTrainingByProject[projectId?.toString() || ''] || false;
const { data: trainingDataList } = usePollingModelReportsQuery(
const { data: fetchedTrainingDataList } = usePollingModelReportsQuery(
projectId as number,
selectedModel ?? 0,
isTraining && !!projectId && !!selectedModel
);
const trainingDataList = useMemo(() => {
return trainingDataByProject[projectId?.toString() || ''] || fetchedTrainingDataList || [];
}, [projectId, trainingDataByProject, fetchedTrainingDataList]);
useEffect(() => {
if (fetchedTrainingDataList) {
saveTrainingData(projectId?.toString() || '', fetchedTrainingDataList);
}
}, [fetchedTrainingDataList, projectId, saveTrainingData]);
const latestData = useMemo(() => {
return (
trainingDataList?.[trainingDataList.length - 1] || {