mirror of
https://github.com/LBRYFoundation/lbry-sdk.git
synced 2025-08-23 17:27:25 +00:00
fix query for windows (999 vars limit)
This commit is contained in:
parent
52317b05bb
commit
f7bd44a4f5
1 changed files with 22 additions and 17 deletions
|
@ -573,16 +573,13 @@ class SQLiteStorage:
|
||||||
}
|
}
|
||||||
|
|
||||||
def _get_supports(transaction):
|
def _get_supports(transaction):
|
||||||
if len(claim_ids) == 1:
|
|
||||||
bind = "=?"
|
|
||||||
else:
|
|
||||||
bind = "in ({})".format(','.join('?' for _ in range(len(claim_ids))))
|
|
||||||
return [
|
return [
|
||||||
_format_support(*support_info)
|
_format_support(*support_info)
|
||||||
for support_info in transaction.execute(
|
for support_info in _batched_select(
|
||||||
f"select * from support where claim_id {bind}",
|
transaction,
|
||||||
|
"select * from support where claim_id in {}",
|
||||||
tuple(claim_ids)
|
tuple(claim_ids)
|
||||||
).fetchall()
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
return self.db.runInteraction(_get_supports)
|
return self.db.runInteraction(_get_supports)
|
||||||
|
@ -756,13 +753,12 @@ class SQLiteStorage:
|
||||||
def get_claims_from_stream_hashes(self, stream_hashes, include_supports=True):
|
def get_claims_from_stream_hashes(self, stream_hashes, include_supports=True):
|
||||||
def _batch_get_claim(transaction):
|
def _batch_get_claim(transaction):
|
||||||
results = {}
|
results = {}
|
||||||
bind = "({})".format(','.join('?' for _ in range(len(stream_hashes))))
|
claim_infos = _batched_select(
|
||||||
claim_infos = transaction.execute(
|
transaction,
|
||||||
"select content_claim.stream_hash, c.* from content_claim "
|
"select content_claim.stream_hash, c.* from content_claim "
|
||||||
"inner join claim c on c.claim_outpoint=content_claim.claim_outpoint "
|
"inner join claim c on c.claim_outpoint=content_claim.claim_outpoint "
|
||||||
"and content_claim.stream_hash in {} order by c.rowid desc".format(bind),
|
"and content_claim.stream_hash in {} order by c.rowid desc",
|
||||||
tuple(stream_hashes)
|
stream_hashes)
|
||||||
).fetchall()
|
|
||||||
channel_id_infos = {}
|
channel_id_infos = {}
|
||||||
for claim_info in claim_infos:
|
for claim_info in claim_infos:
|
||||||
if claim_info[7]:
|
if claim_info[7]:
|
||||||
|
@ -773,11 +769,12 @@ class SQLiteStorage:
|
||||||
stream_hash = claim_info[0]
|
stream_hash = claim_info[0]
|
||||||
result = _format_claim_response(*claim_info[1:])
|
result = _format_claim_response(*claim_info[1:])
|
||||||
results[stream_hash] = result
|
results[stream_hash] = result
|
||||||
bind = "({})".format(','.join('?' for _ in range(len(channel_id_infos))))
|
channel_names = _batched_select(
|
||||||
for claim_id, channel_name in transaction.execute(
|
transaction,
|
||||||
f"select claim_id, claim_name from claim where claim_id in {bind}",
|
"select claim_id, claim_name from claim where claim_id in {}",
|
||||||
tuple(channel_id_infos.keys())
|
tuple(channel_id_infos.keys())
|
||||||
).fetchall():
|
)
|
||||||
|
for claim_id, channel_name in channel_names:
|
||||||
for stream_hash in channel_id_infos[claim_id]:
|
for stream_hash in channel_id_infos[claim_id]:
|
||||||
results[stream_hash]['channel_name'] = channel_name
|
results[stream_hash]['channel_name'] = channel_name
|
||||||
return results
|
return results
|
||||||
|
@ -892,3 +889,11 @@ def _format_claim_response(outpoint, claim_id, name, amount, height, serialized,
|
||||||
"channel_name": None
|
"channel_name": None
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
def _batched_select(transaction, query, parameters):
|
||||||
|
for start_index in range(0, len(parameters), 900):
|
||||||
|
current_batch = parameters[start_index:start_index+900]
|
||||||
|
bind = "({})".format(','.join('?' for _ in range(len(current_batch))))
|
||||||
|
for result in transaction.execute(query.format(bind), current_batch):
|
||||||
|
yield result
|
||||||
|
|
Loading…
Add table
Reference in a new issue