diff --git a/lbry/db/queries/search.py b/lbry/db/queries/search.py index de5e9e086..b3135aa1f 100644 --- a/lbry/db/queries/search.py +++ b/lbry/db/queries/search.py @@ -103,7 +103,7 @@ def search_support_count(**constraints) -> int: CHANNEL_CLAIM = Claim.alias('channel') -BASE_SELECT_CLAIM_COLUMNS = [Claim.c.claim_hash.distinct()] + BASE_SELECT_TXO_COLUMNS + [ +BASE_SELECT_CLAIM_COLUMNS = BASE_SELECT_TXO_COLUMNS + [ Claim.c.activation_height, Claim.c.takeover_height, Claim.c.creation_height, @@ -149,7 +149,7 @@ def select_claims(cols: List = None, for_count=False, **constraints) -> Select: if column == 'name': column = 'claim_name' nulls_last = '' - if column == 'release_time': + if column in ('trending_group', 'trending_mixed', 'release_time'): nulls_last = ' NULLs LAST' table = "trend" if column.startswith('trend') else "claim" sql_order_by.append( diff --git a/lbry/schema/result.py b/lbry/schema/result.py index 2e889dcd5..00e69daea 100644 --- a/lbry/schema/result.py +++ b/lbry/schema/result.py @@ -24,12 +24,11 @@ def set_reference(reference, claim_hash, rows): class Censor: - __slots__ = 'level', 'censored', 'total' + __slots__ = 'level', 'censored' def __init__(self, level=1): self.level = level self.censored = {} - self.total = 0 def apply(self, rows): return [row for row in rows if not self.censor(row)] @@ -38,16 +37,15 @@ class Censor: was_censored = row['censor_type'] >= self.level if was_censored: censoring_channel_hash = row['censor_owner_hash'] - self.censored.setdefault(censoring_channel_hash, 0) - self.censored[censoring_channel_hash] += 1 - self.total += 1 + self.censored.setdefault(censoring_channel_hash, set()) + self.censored[censoring_channel_hash].add(row['tx_hash']) return was_censored def to_message(self, outputs: OutputsMessage, extra_txo_rows): - outputs.blocked_total = self.total + outputs.blocked_total = len(self.censored) for censoring_channel_hash, count in self.censored.items(): blocked = outputs.blocked.add() - blocked.count = count + blocked.count = len(count) set_reference(blocked.channel, censoring_channel_hash, extra_txo_rows) diff --git a/tests/integration/blockchain/test_blockchain.py b/tests/integration/blockchain/test_blockchain.py index d67b37c1f..d7095adc0 100644 --- a/tests/integration/blockchain/test_blockchain.py +++ b/tests/integration/blockchain/test_blockchain.py @@ -1394,17 +1394,17 @@ class TestClaimtrieSync(SyncingBlockchainTestCase): await self.generate(1) results = await self.db.search_claims(channel="@some_channel") self.assertEqual(len(results.rows), 1) - self.assertEqual(results.censor.censored.get(moderator_chan.claim_hash), 1) + self.assertEqual(len(results.censor.censored.get(moderator_chan.claim_hash)), 1) await self.create_claim(sign=user_chan, name="reposting_bad", repost=bad_content.claim_id) await self.generate(1) results = await self.db.search_claims(channel="@some_channel") self.assertEqual(len(results.rows), 1) - self.assertEqual(results.censor.censored.get(moderator_chan.claim_hash), 2) + self.assertEqual(len(results.censor.censored.get(moderator_chan.claim_hash)), 2) await self.create_claim(sign=moderator_chan, name="blocking_bad", repost=user_chan.claim_id) await self.generate(1) results = await self.db.search_claims(channel="@some_channel") self.assertEqual(len(results.rows), 0) - self.assertEqual(results.censor.censored.get(moderator_chan.claim_hash), 3) # good, bad and repost + self.assertEqual(len(results.censor.censored.get(moderator_chan.claim_hash)), 3) # good, bad and repost # direct resolves are still possible result = await self.db.resolve([bad_content.permanent_url]) self.assertEqual(bad_content.claim_id, result[bad_content.permanent_url].claim_id)