mirror of
https://github.com/LBRYFoundation/lbry-sdk.git
synced 2025-08-23 17:27:25 +00:00
automatically batch large resolve requests
This commit is contained in:
parent
5b29894048
commit
d615f6761a
2 changed files with 12 additions and 1 deletions
|
@ -752,7 +752,11 @@ class Ledger(metaclass=LedgerRegistry):
|
||||||
|
|
||||||
async def resolve(self, accounts, urls, **kwargs):
|
async def resolve(self, accounts, urls, **kwargs):
|
||||||
resolve = partial(self.network.retriable_call, self.network.resolve)
|
resolve = partial(self.network.retriable_call, self.network.resolve)
|
||||||
txos = (await self._inflate_outputs(resolve(urls), accounts, **kwargs))[0]
|
urls_copy = list(urls)
|
||||||
|
txos = []
|
||||||
|
while urls_copy:
|
||||||
|
batch, urls_copy = urls_copy[:500], urls_copy[500:]
|
||||||
|
txos.extend((await self._inflate_outputs(resolve(batch), accounts, **kwargs))[0])
|
||||||
assert len(urls) == len(txos), "Mismatch between urls requested for resolve and responses received."
|
assert len(urls) == len(txos), "Mismatch between urls requested for resolve and responses received."
|
||||||
result = {}
|
result = {}
|
||||||
for url, txo in zip(urls, txos):
|
for url, txo in zip(urls, txos):
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import os.path
|
import os.path
|
||||||
import tempfile
|
import tempfile
|
||||||
import logging
|
import logging
|
||||||
|
import asyncio
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
@ -79,6 +80,12 @@ class ClaimSearchCommand(ClaimTestCase):
|
||||||
] * 23828
|
] * 23828
|
||||||
self.assertListEqual([], await self.claim_search(claim_ids=claim_ids))
|
self.assertListEqual([], await self.claim_search(claim_ids=claim_ids))
|
||||||
|
|
||||||
|
# this should do nothing... if the resolve (which is retried) results in the server disconnecting,
|
||||||
|
# it kerplodes
|
||||||
|
await asyncio.wait_for(self.daemon.jsonrpc_resolve([
|
||||||
|
f'0000000000000000000000000000000000000000{i}' for i in range(30000)
|
||||||
|
]), 30)
|
||||||
|
|
||||||
# 23829 claim ids makes the request just large enough
|
# 23829 claim ids makes the request just large enough
|
||||||
claim_ids = [
|
claim_ids = [
|
||||||
'0000000000000000000000000000000000000000',
|
'0000000000000000000000000000000000000000',
|
||||||
|
|
Loading…
Add table
Reference in a new issue