Skip to content

Commit

Permalink
feat: do requests in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Jan 29, 2025
1 parent 0e2b5cb commit c5d1359
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/components/ENSListPage/ENSListPage.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 = {
Expand Down
33 changes: 2 additions & 31 deletions src/components/WorldListPage/WorldListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,6 @@ const WorldListPage: React.FC<Props> = 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'
Expand Down Expand Up @@ -179,7 +161,7 @@ const WorldListPage: React.FC<Props> = 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 (
<>
Expand Down Expand Up @@ -265,18 +247,7 @@ const WorldListPage: React.FC<Props> = props => {
</Container>
</>
)
}, [
tab,
ensList,
externalNames,
handleClaimENS,
paginate,
renderSortDropdown,
renderWorldSize,
renderWorldStatus,
handlePageChange,
ensTotal
])
}, [tab, ensList, externalNames, handleClaimENS, renderSortDropdown, renderWorldSize, renderWorldStatus, handlePageChange, ensTotal])

const renderEmptyPage = useCallback(() => {
return (
Expand Down
3 changes: 2 additions & 1 deletion src/components/WorldListPage/WorldListPage.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}

Expand Down
12 changes: 7 additions & 5 deletions src/modules/ens/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ENS>)[] = domains.map(data => {
const promisesOfENS: (() => Promise<ENS>)[] = domains.map((data: string) => {
return async () => {
const name = data
const subdomain = `${data.toLowerCase()}.dcl.eth`
Expand Down

0 comments on commit c5d1359

Please sign in to comment.