Skip to content
Snippets Groups Projects

Resolve "Search speed"

Merged Piotr Gawron requested to merge 279-search-speed into development
4 files
+ 14
16
Compare changes
  • Side-by-side
  • Inline
Files
4
import { bioEntityContentSchema } from '@/models/bioEntityContentSchema';
import { submapConnection } from '@/models/submapConnection';
import { apiPath } from '@/redux/apiPath';
import { axiosInstance, axiosInstanceNewAPI } from '@/services/api/utils/axiosInstance';
import { BioEntityContent, BioEntityResponse, SubmapConnection } from '@/types/models';
import { BioEntity, SubmapConnection } from '@/types/models';
import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema';
import { createAsyncThunk } from '@reduxjs/toolkit';
import { z } from 'zod';
import { getError } from '@/utils/error-report/getError';
import { bioEntitySchema } from '@/models/bioEntitySchema';
import { MULTI_BIO_ENTITY_FETCHING_ERROR_PREFIX } from '../bioEntity.constants';
export const getSubmapConnectionsBioEntity = createAsyncThunk<BioEntityContent[]>(
export const getSubmapConnectionsBioEntity = createAsyncThunk<BioEntity[]>(
'project/getSubmapConnectionsBioEntity',
async () => {
try {
@@ -20,21 +20,20 @@ export const getSubmapConnectionsBioEntity = createAsyncThunk<BioEntityContent[]
throw new Error('Submap connections validation error');
}
const searchQueries = response.data.map(({ from }) => `${from.id}`);
const targetElements = response.data.map(({ from }) => from);
const asyncFetchBioEntityFunctions = searchQueries.map(searchQuery =>
axiosInstanceNewAPI.get<BioEntityResponse>(
apiPath.getBioEntityContentsStringWithQuery({ searchQuery, isPerfectMatch: true }),
const asyncFetchBioEntityFunctions = targetElements.map(targetElement =>
axiosInstanceNewAPI.get<BioEntity>(
apiPath.getElementById(targetElement.id, targetElement.modelId),
),
);
const bioEntityContentResponse = await Promise.all(asyncFetchBioEntityFunctions);
const bioEntityContents = bioEntityContentResponse
.map(contentResponse => contentResponse?.data?.content || [])
.map(contentResponse => contentResponse.data)
.flat()
.filter(content => bioEntityContentSchema.safeParse(content).success)
.filter(payload => 'bioEntity' in payload || {});
.filter(content => bioEntitySchema.safeParse(content).success);
return bioEntityContents;
} catch (error) {
Loading