forked from LBRYCommunity/lbry-sdk
add batching support to get_supports and tests
This commit is contained in:
parent
d55ded78ee
commit
ca86af736e
2 changed files with 26 additions and 2 deletions
|
@ -552,7 +552,7 @@ class SQLiteStorage(object):
|
|||
)
|
||||
return self.db.runInteraction(_save_support)
|
||||
|
||||
def get_supports(self, claim_id):
|
||||
def get_supports(self, *claim_ids):
|
||||
def _format_support(outpoint, supported_id, amount, address):
|
||||
return {
|
||||
"txid": outpoint.split(":")[0],
|
||||
|
@ -563,10 +563,15 @@ class SQLiteStorage(object):
|
|||
}
|
||||
|
||||
def _get_supports(transaction):
|
||||
if len(claim_ids) == 1:
|
||||
bind = "=?"
|
||||
else:
|
||||
bind = "in ({})".format(','.join('?' for _ in range(len(claim_ids))))
|
||||
return [
|
||||
_format_support(*support_info)
|
||||
for support_info in transaction.execute(
|
||||
"select * from support where claim_id=?", (claim_id, )
|
||||
"select * from support where claim_id {}".format(bind),
|
||||
tuple(claim_ids)
|
||||
).fetchall()
|
||||
]
|
||||
|
||||
|
|
|
@ -163,6 +163,25 @@ class BlobStorageTests(StorageTest):
|
|||
self.assertEqual(blob_hashes, [])
|
||||
|
||||
|
||||
class SupportsStorageTests(StorageTest):
|
||||
@defer.inlineCallbacks
|
||||
def test_supports_storage(self):
|
||||
claim_ids = [random_lbry_hash() for _ in range(10)]
|
||||
random_supports = [{"txid": random_lbry_hash(), "nout":i, "address": "addr{}".format(i), "amount": i}
|
||||
for i in range(20)]
|
||||
expected_supports = {}
|
||||
for idx, claim_id in enumerate(claim_ids):
|
||||
yield self.storage.save_supports(claim_id, random_supports[idx*2:idx*2+2])
|
||||
for random_support in random_supports[idx*2:idx*2+2]:
|
||||
random_support['claim_id'] = claim_id
|
||||
expected_supports.setdefault(claim_id, []).append(random_support)
|
||||
supports = yield self.storage.get_supports(claim_ids[0])
|
||||
self.assertEqual(supports, expected_supports[claim_ids[0]])
|
||||
all_supports = yield self.storage.get_supports(*claim_ids)
|
||||
for support in all_supports:
|
||||
self.assertIn(support, expected_supports[support['claim_id']])
|
||||
|
||||
|
||||
class StreamStorageTests(StorageTest):
|
||||
@defer.inlineCallbacks
|
||||
def test_store_stream(self, stream_hash=None):
|
||||
|
|
Loading…
Reference in a new issue