Skip to content

Commit 0225097

Browse files
authored
Merge pull request #99 from autonomys/fix-om-order
fix: ensure order in batched request
2 parents c11fb38 + 5ed8e06 commit 0225097

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

services/object-mapping-indexer/src/useCases/objectMapping.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,20 @@ const getObjectMappings = async (
7676
): Promise<ObjectMapping[]> => {
7777
const objectMappings = await objectMappingRepository.getByHashes(hashes)
7878

79-
return objectMappings.map((e) => [e.hash, e.pieceIndex, e.pieceOffset])
79+
// Create a map of hash to object mapping for quick lookup
80+
const mappingsByHash = new Map<string, ObjectMapping>(
81+
objectMappings.map((e) => [e.hash, [e.hash, e.pieceIndex, e.pieceOffset]]),
82+
)
83+
84+
// Return results in the same order as input hashes
85+
return hashes.map((hash) => {
86+
const mapping = mappingsByHash.get(hash)
87+
if (!mapping) {
88+
throw new Error('Object mapping not found')
89+
}
90+
91+
return mapping
92+
})
8093
}
8194

8295
export const objectMappingUseCase = {

0 commit comments

Comments
 (0)