Skip to content

Commit

Permalink
fix: Requesting coordines for more than 150 hashes (#3183)
Browse files Browse the repository at this point in the history
  • Loading branch information
LautaroPetaccio authored Sep 13, 2024
1 parent 5c60794 commit 0bfd8b9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/lib/array.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export function difference<T = any>(left: T[], right: T[]) {
return left.filter(x => right.indexOf(x) === -1)
}

export const chunk = <T>(arr: T[], size: number): T[][] =>
Array.from({ length: Math.ceil(arr.length / size) }, (_, i) => arr.slice(i * size, i * size + size))
5 changes: 1 addition & 4 deletions src/modules/curations/itemCuration/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isErrorWithMessage } from 'decentraland-dapps/dist/lib/error'
import { BuilderAPI } from 'lib/api/builder'
import { FetchCollectionItemsSuccessAction, FETCH_COLLECTION_ITEMS_SUCCESS } from 'modules/item/actions'
import { isThirdParty } from 'lib/urn'
import { Item } from 'modules/item/types'
import { chunk } from 'lib/array'
import {
fetchItemCurationFailure,
FetchItemCurationRequestAction,
Expand All @@ -21,9 +21,6 @@ import { ItemCuration } from './types'
const MAX_ITEM_CURATIONS = 30
const REQUESTS_BATCH_SIZE = 10

const chunk = (arr: Item[], size: number) =>
Array.from({ length: Math.ceil(arr.length / size) }, (_, i) => arr.slice(i * size, i * size + size))

export function* itemCurationSaga(builder: BuilderAPI) {
yield takeEvery(FETCH_ITEM_CURATION_REQUEST, handleFetchItemCurationRequest)
yield takeEvery(FETCH_ITEM_CURATIONS_REQUEST, handleFetchItemCurationsRequest)
Expand Down
7 changes: 6 additions & 1 deletion src/modules/ens/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ethers } from 'ethers'
import { Entity } from '@dcl/schemas'
import { PEER_URL, getCatalystContentUrl } from 'lib/api/peer'
import { extractEntityId } from 'lib/urn'
import { chunk } from 'lib/array'
import { WorldInfo, WorldsAPI } from 'lib/api/worlds'
import { Land, LandType } from 'modules/land/types'
import { ENS, WorldStatus } from './types'
Expand Down Expand Up @@ -92,7 +93,11 @@ export async function getLandRedirectionHashes(builderClient: BuilderClient, lan
const coordsList = lands.map(land => getCenter(getSelection(land))).map(coords => ({ x: coords[0], y: coords[1] }))
let coordsWithHashesList: (LandCoords & LandHashes)[] = []
if (coordsList.length > 0) {
coordsWithHashesList = await builderClient.getLandRedirectionHashes(coordsList, getCurrentLocale().locale)
for (const coordsBatch of chunk(coordsList, 145)) {
coordsWithHashesList = coordsWithHashesList.concat(
await builderClient.getLandRedirectionHashes(coordsBatch, getCurrentLocale().locale)
)
}
}
const landHashes: { id: string; hash: string }[] = []

Expand Down

0 comments on commit 0bfd8b9

Please sign in to comment.