Skip to content

Commit 0bfd8b9

Browse files
fix: Requesting coordines for more than 150 hashes (#3183)
1 parent 5c60794 commit 0bfd8b9

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/lib/array.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
export function difference<T = any>(left: T[], right: T[]) {
22
return left.filter(x => right.indexOf(x) === -1)
33
}
4+
5+
export const chunk = <T>(arr: T[], size: number): T[][] =>
6+
Array.from({ length: Math.ceil(arr.length / size) }, (_, i) => arr.slice(i * size, i * size + size))

src/modules/curations/itemCuration/sagas.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { isErrorWithMessage } from 'decentraland-dapps/dist/lib/error'
44
import { BuilderAPI } from 'lib/api/builder'
55
import { FetchCollectionItemsSuccessAction, FETCH_COLLECTION_ITEMS_SUCCESS } from 'modules/item/actions'
66
import { isThirdParty } from 'lib/urn'
7-
import { Item } from 'modules/item/types'
7+
import { chunk } from 'lib/array'
88
import {
99
fetchItemCurationFailure,
1010
FetchItemCurationRequestAction,
@@ -21,9 +21,6 @@ import { ItemCuration } from './types'
2121
const MAX_ITEM_CURATIONS = 30
2222
const REQUESTS_BATCH_SIZE = 10
2323

24-
const chunk = (arr: Item[], size: number) =>
25-
Array.from({ length: Math.ceil(arr.length / size) }, (_, i) => arr.slice(i * size, i * size + size))
26-
2724
export function* itemCurationSaga(builder: BuilderAPI) {
2825
yield takeEvery(FETCH_ITEM_CURATION_REQUEST, handleFetchItemCurationRequest)
2926
yield takeEvery(FETCH_ITEM_CURATIONS_REQUEST, handleFetchItemCurationsRequest)

src/modules/ens/utils.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ethers } from 'ethers'
22
import { Entity } from '@dcl/schemas'
33
import { PEER_URL, getCatalystContentUrl } from 'lib/api/peer'
44
import { extractEntityId } from 'lib/urn'
5+
import { chunk } from 'lib/array'
56
import { WorldInfo, WorldsAPI } from 'lib/api/worlds'
67
import { Land, LandType } from 'modules/land/types'
78
import { ENS, WorldStatus } from './types'
@@ -92,7 +93,11 @@ export async function getLandRedirectionHashes(builderClient: BuilderClient, lan
9293
const coordsList = lands.map(land => getCenter(getSelection(land))).map(coords => ({ x: coords[0], y: coords[1] }))
9394
let coordsWithHashesList: (LandCoords & LandHashes)[] = []
9495
if (coordsList.length > 0) {
95-
coordsWithHashesList = await builderClient.getLandRedirectionHashes(coordsList, getCurrentLocale().locale)
96+
for (const coordsBatch of chunk(coordsList, 145)) {
97+
coordsWithHashesList = coordsWithHashesList.concat(
98+
await builderClient.getLandRedirectionHashes(coordsBatch, getCurrentLocale().locale)
99+
)
100+
}
96101
}
97102
const landHashes: { id: string; hash: string }[] = []
98103

0 commit comments

Comments
 (0)