forked from LBRYCommunity/lbry-sdk
test boundaries, make limit a constant
This commit is contained in:
parent
28ae7f81e9
commit
c1c7e30ec9
2 changed files with 21 additions and 9 deletions
|
@ -235,10 +235,20 @@ class TestQueries(AsyncioTestCase):
|
|||
|
||||
self.ledger.db.db.execute_fetchall = check_parameters_length
|
||||
account = await self.create_account()
|
||||
tx = await self.create_tx_from_nothing(account, 1)
|
||||
for _ in range(1200):
|
||||
tx = await self.create_tx_from_txo(tx.outputs[0], account, 1)
|
||||
await self.ledger.db.get_transactions()
|
||||
tx = await self.create_tx_from_nothing(account, 0)
|
||||
for height in range(1200):
|
||||
tx = await self.create_tx_from_txo(tx.outputs[0], account, height=height)
|
||||
variable_limit = self.ledger.db.MAX_QUERY_VARIABLES
|
||||
for limit in range(variable_limit-2, variable_limit+2):
|
||||
txs = await self.ledger.db.get_transactions(limit=limit, order_by='height asc')
|
||||
self.assertEqual(len(txs), limit)
|
||||
inputs, outputs, last_tx = set(), set(), txs[0]
|
||||
for tx in txs[1:]:
|
||||
self.assertEqual(len(tx.inputs), 1)
|
||||
self.assertEqual(tx.inputs[0].txo_ref.tx_ref.id, last_tx.id)
|
||||
self.assertEqual(len(tx.outputs), 1)
|
||||
last_tx = tx
|
||||
|
||||
|
||||
async def test_queries(self):
|
||||
self.assertEqual(0, await self.ledger.db.get_address_count())
|
||||
|
|
|
@ -198,6 +198,7 @@ def rows_to_dict(rows, fields):
|
|||
class SQLiteMixin:
|
||||
|
||||
CREATE_TABLES_QUERY: str
|
||||
MAX_QUERY_VARIABLES = 900
|
||||
|
||||
def __init__(self, path):
|
||||
self._db_path = path
|
||||
|
@ -396,7 +397,7 @@ class BaseDatabase(SQLiteMixin):
|
|||
|
||||
tx_rows = await self.select_transactions(
|
||||
'txid, raw, height, position, is_verified',
|
||||
order_by=["height=0 DESC", "height DESC", "position DESC"],
|
||||
order_by=constraints.pop('order_by', ["height=0 DESC", "height DESC", "position DESC"]),
|
||||
**constraints
|
||||
)
|
||||
|
||||
|
@ -412,23 +413,24 @@ class BaseDatabase(SQLiteMixin):
|
|||
for txi in txs[-1].inputs:
|
||||
txi_txoids.append(txi.txo_ref.id)
|
||||
|
||||
step = self.MAX_QUERY_VARIABLES
|
||||
annotated_txos = {}
|
||||
for offset in range(0, len(txids), 900):
|
||||
for offset in range(0, len(txids), step):
|
||||
annotated_txos.update({
|
||||
txo.id: txo for txo in
|
||||
(await self.get_txos(
|
||||
my_account=my_account,
|
||||
txid__in=txids[offset:offset+900],
|
||||
txid__in=txids[offset:offset+step],
|
||||
))
|
||||
})
|
||||
|
||||
referenced_txos = {}
|
||||
for offset in range(0, len(txi_txoids), 900):
|
||||
for offset in range(0, len(txi_txoids), step):
|
||||
referenced_txos.update({
|
||||
txo.id: txo for txo in
|
||||
(await self.get_txos(
|
||||
my_account=my_account,
|
||||
txoid__in=txi_txoids[offset:offset+900],
|
||||
txoid__in=txi_txoids[offset:offset+step],
|
||||
))
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue