From c5d1359b80bbbbd2c021fcdf2542475db71094ea Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Wed, 29 Jan 2025 10:57:50 +0100 Subject: [PATCH] feat: do requests in parallel --- .../ENSListPage/ENSListPage.types.ts | 3 +- .../WorldListPage/WorldListPage.tsx | 33 ++----------------- .../WorldListPage/WorldListPage.types.ts | 3 +- src/modules/ens/sagas.ts | 12 ++++--- 4 files changed, 13 insertions(+), 38 deletions(-) diff --git a/src/components/ENSListPage/ENSListPage.types.ts b/src/components/ENSListPage/ENSListPage.types.ts index a3b2bf3da..c73d6aa82 100644 --- a/src/components/ENSListPage/ENSListPage.types.ts +++ b/src/components/ENSListPage/ENSListPage.types.ts @@ -2,6 +2,7 @@ import { Dispatch } from 'redux' import { ENS } from 'modules/ens/types' import { Land } from 'modules/land/types' import { openModal } from 'decentraland-dapps/dist/modules/modal/actions' +import { fetchENSListRequest } from 'modules/ens/actions' import { Avatar } from '@dcl/schemas' export enum SortBy { @@ -21,7 +22,7 @@ export type Props = { avatar: Avatar | null total: number onOpenModal: typeof openModal - onFetchENSList: (first: number, skip: number) => void + onFetchENSList: typeof fetchENSListRequest } export type State = { diff --git a/src/components/WorldListPage/WorldListPage.tsx b/src/components/WorldListPage/WorldListPage.tsx index 16b4bc554..b255280b8 100644 --- a/src/components/WorldListPage/WorldListPage.tsx +++ b/src/components/WorldListPage/WorldListPage.tsx @@ -115,24 +115,6 @@ const WorldListPage: React.FC = props => { ) }, [sortBy, setSortBy]) - const paginate = useCallback((): ENS[] => { - const list = tab === TabType.DCL ? ensList : externalNames - - return list.sort((a: ENS, b: ENS) => { - switch (sortBy) { - case SortBy.ASC: { - return a.subdomain.toLowerCase() > b.subdomain.toLowerCase() ? 1 : -1 - } - case SortBy.DESC: { - return a.subdomain.toLowerCase() < b.subdomain.toLowerCase() ? 1 : -1 - } - default: { - return 0 - } - } - }) - }, [ensList, externalNames, sortBy, tab]) - const renderWorldStatus = useCallback( (ens: ENS) => { let status = isWorldDeployed(deploymentsByWorlds, ens) ? 'active' : 'inactive' @@ -179,7 +161,7 @@ const WorldListPage: React.FC = props => { const renderList = useCallback(() => { const total = tab === TabType.DCL ? ensTotal : externalNames.length const totalPages = Math.ceil(total / PAGE_SIZE) - const paginatedItems = paginate() + const paginatedItems = tab === TabType.DCL ? ensList : externalNames return ( <> @@ -265,18 +247,7 @@ const WorldListPage: React.FC = props => { ) - }, [ - tab, - ensList, - externalNames, - handleClaimENS, - paginate, - renderSortDropdown, - renderWorldSize, - renderWorldStatus, - handlePageChange, - ensTotal - ]) + }, [tab, ensList, externalNames, handleClaimENS, renderSortDropdown, renderWorldSize, renderWorldStatus, handlePageChange, ensTotal]) const renderEmptyPage = useCallback(() => { return ( diff --git a/src/components/WorldListPage/WorldListPage.types.ts b/src/components/WorldListPage/WorldListPage.types.ts index d8238113c..c98d6e2ca 100644 --- a/src/components/WorldListPage/WorldListPage.types.ts +++ b/src/components/WorldListPage/WorldListPage.types.ts @@ -2,6 +2,7 @@ import { Dispatch } from 'redux' import { clearDeploymentRequest } from 'modules/deployment/actions' import { Deployment } from 'modules/deployment/types' import { ENS } from 'modules/ens/types' +import { fetchENSListRequest } from 'modules/ens/actions' import { Project } from 'modules/project/types' import { WorldPermissions, WorldsWalletStats } from 'lib/api/worlds' import { WorldsYourStorageModalMetadata } from 'components/Modals/WorldsYourStorageModal/WorldsYourStorageModal.types' @@ -29,7 +30,7 @@ export type Props = { getProfiles: (worldName: string) => void onUnpublishWorld: typeof clearDeploymentRequest onFetchContributableNames: () => void - onFetchENSList: (first: number, skip: number) => void + onFetchENSList: typeof fetchENSListRequest ensTotal: number } diff --git a/src/modules/ens/sagas.ts b/src/modules/ens/sagas.ts index 3899265d4..62c2fb049 100644 --- a/src/modules/ens/sagas.ts +++ b/src/modules/ens/sagas.ts @@ -367,16 +367,18 @@ export function* ensSaga(builderClient: BuilderClient, ensApi: ENSApi, worldsAPI ) const defaultPageSize = 12 const { first = defaultPageSize, skip = 0 } = action.payload - let domains: string[] = yield call([marketplace, 'fetchENSList'], address, first, skip) - const totalDomains: number = yield call([marketplace, 'fetchENSListCount'], address) - const bannedDomains: string[] = yield call(fetchBannedDomains) - domains = domains.filter(domain => !bannedDomains.includes(domain)) + const [fetchedDomains, totalDomains, bannedDomains]: [string[], number, string[]] = yield all([ + call([marketplace, 'fetchENSList'], address, first, skip), + call([marketplace, 'fetchENSListCount'], address), + call(fetchBannedDomains) + ]) + const domains = fetchedDomains.filter((domain: string) => !bannedDomains.includes(domain)) const REQUESTS_BATCH_SIZE = 25 const queue = new PQueue({ concurrency: REQUESTS_BATCH_SIZE }) const worldsDeployed: string[] = [] - const promisesOfENS: (() => Promise)[] = domains.map(data => { + const promisesOfENS: (() => Promise)[] = domains.map((data: string) => { return async () => { const name = data const subdomain = `${data.toLowerCase()}.dcl.eth`