Merge pull request #2917 from lbryio/faster-repost-search-query
improve how claim search query handles reposts
This commit is contained in:
commit
58640c1521
1 changed files with 26 additions and 10 deletions
|
@ -545,6 +545,14 @@ def _apply_constraints_for_array_attributes(constraints, attr, cleaner, for_coun
|
||||||
f':$any_{attr}{i}' for i in range(len(any_items))
|
f':$any_{attr}{i}' for i in range(len(any_items))
|
||||||
)
|
)
|
||||||
if for_count or attr == 'tag':
|
if for_count or attr == 'tag':
|
||||||
|
if attr == 'tag':
|
||||||
|
any_queries[f'#_any_{attr}'] = f"""
|
||||||
|
(claim.claim_type != {CLAIM_TYPES['repost']}
|
||||||
|
AND claim.claim_hash IN (SELECT claim_hash FROM tag WHERE tag IN ({values}))) OR
|
||||||
|
(claim.claim_type == {CLAIM_TYPES['repost']} AND
|
||||||
|
claim.reposted_claim_hash IN (SELECT claim_hash FROM tag WHERE tag IN ({values})))
|
||||||
|
"""
|
||||||
|
else:
|
||||||
any_queries[f'#_any_{attr}'] = f"""
|
any_queries[f'#_any_{attr}'] = f"""
|
||||||
{CLAIM_HASH_OR_REPOST_HASH_SQL} IN (
|
{CLAIM_HASH_OR_REPOST_HASH_SQL} IN (
|
||||||
SELECT claim_hash FROM {attr} WHERE {attr} IN ({values})
|
SELECT claim_hash FROM {attr} WHERE {attr} IN ({values})
|
||||||
|
@ -596,6 +604,14 @@ def _apply_constraints_for_array_attributes(constraints, attr, cleaner, for_coun
|
||||||
f':$not_{attr}{i}' for i in range(len(not_items))
|
f':$not_{attr}{i}' for i in range(len(not_items))
|
||||||
)
|
)
|
||||||
if for_count:
|
if for_count:
|
||||||
|
if attr == 'tag':
|
||||||
|
constraints[f'#_not_{attr}'] = f"""
|
||||||
|
(claim.claim_type != {CLAIM_TYPES['repost']}
|
||||||
|
AND claim.claim_hash NOT IN (SELECT claim_hash FROM tag WHERE tag IN ({values}))) AND
|
||||||
|
(claim.claim_type == {CLAIM_TYPES['repost']} AND
|
||||||
|
claim.reposted_claim_hash NOT IN (SELECT claim_hash FROM tag WHERE tag IN ({values})))
|
||||||
|
"""
|
||||||
|
else:
|
||||||
constraints[f'#_not_{attr}'] = f"""
|
constraints[f'#_not_{attr}'] = f"""
|
||||||
{CLAIM_HASH_OR_REPOST_HASH_SQL} NOT IN (
|
{CLAIM_HASH_OR_REPOST_HASH_SQL} NOT IN (
|
||||||
SELECT claim_hash FROM {attr} WHERE {attr} IN ({values})
|
SELECT claim_hash FROM {attr} WHERE {attr} IN ({values})
|
||||||
|
|
Loading…
Reference in a new issue