fix compat issues between postgres/sqlite
This commit is contained in:
parent
c1c9c2883a
commit
09aa3039e9
3 changed files with 10 additions and 12 deletions
|
@ -103,7 +103,7 @@ def search_support_count(**constraints) -> int:
|
||||||
|
|
||||||
|
|
||||||
CHANNEL_CLAIM = Claim.alias('channel')
|
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.activation_height,
|
||||||
Claim.c.takeover_height,
|
Claim.c.takeover_height,
|
||||||
Claim.c.creation_height,
|
Claim.c.creation_height,
|
||||||
|
@ -149,7 +149,7 @@ def select_claims(cols: List = None, for_count=False, **constraints) -> Select:
|
||||||
if column == 'name':
|
if column == 'name':
|
||||||
column = 'claim_name'
|
column = 'claim_name'
|
||||||
nulls_last = ''
|
nulls_last = ''
|
||||||
if column == 'release_time':
|
if column in ('trending_group', 'trending_mixed', 'release_time'):
|
||||||
nulls_last = ' NULLs LAST'
|
nulls_last = ' NULLs LAST'
|
||||||
table = "trend" if column.startswith('trend') else "claim"
|
table = "trend" if column.startswith('trend') else "claim"
|
||||||
sql_order_by.append(
|
sql_order_by.append(
|
||||||
|
|
|
@ -24,12 +24,11 @@ def set_reference(reference, claim_hash, rows):
|
||||||
|
|
||||||
class Censor:
|
class Censor:
|
||||||
|
|
||||||
__slots__ = 'level', 'censored', 'total'
|
__slots__ = 'level', 'censored'
|
||||||
|
|
||||||
def __init__(self, level=1):
|
def __init__(self, level=1):
|
||||||
self.level = level
|
self.level = level
|
||||||
self.censored = {}
|
self.censored = {}
|
||||||
self.total = 0
|
|
||||||
|
|
||||||
def apply(self, rows):
|
def apply(self, rows):
|
||||||
return [row for row in rows if not self.censor(row)]
|
return [row for row in rows if not self.censor(row)]
|
||||||
|
@ -38,16 +37,15 @@ class Censor:
|
||||||
was_censored = row['censor_type'] >= self.level
|
was_censored = row['censor_type'] >= self.level
|
||||||
if was_censored:
|
if was_censored:
|
||||||
censoring_channel_hash = row['censor_owner_hash']
|
censoring_channel_hash = row['censor_owner_hash']
|
||||||
self.censored.setdefault(censoring_channel_hash, 0)
|
self.censored.setdefault(censoring_channel_hash, set())
|
||||||
self.censored[censoring_channel_hash] += 1
|
self.censored[censoring_channel_hash].add(row['tx_hash'])
|
||||||
self.total += 1
|
|
||||||
return was_censored
|
return was_censored
|
||||||
|
|
||||||
def to_message(self, outputs: OutputsMessage, extra_txo_rows):
|
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():
|
for censoring_channel_hash, count in self.censored.items():
|
||||||
blocked = outputs.blocked.add()
|
blocked = outputs.blocked.add()
|
||||||
blocked.count = count
|
blocked.count = len(count)
|
||||||
set_reference(blocked.channel, censoring_channel_hash, extra_txo_rows)
|
set_reference(blocked.channel, censoring_channel_hash, extra_txo_rows)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1394,17 +1394,17 @@ class TestClaimtrieSync(SyncingBlockchainTestCase):
|
||||||
await self.generate(1)
|
await self.generate(1)
|
||||||
results = await self.db.search_claims(channel="@some_channel")
|
results = await self.db.search_claims(channel="@some_channel")
|
||||||
self.assertEqual(len(results.rows), 1)
|
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.create_claim(sign=user_chan, name="reposting_bad", repost=bad_content.claim_id)
|
||||||
await self.generate(1)
|
await self.generate(1)
|
||||||
results = await self.db.search_claims(channel="@some_channel")
|
results = await self.db.search_claims(channel="@some_channel")
|
||||||
self.assertEqual(len(results.rows), 1)
|
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.create_claim(sign=moderator_chan, name="blocking_bad", repost=user_chan.claim_id)
|
||||||
await self.generate(1)
|
await self.generate(1)
|
||||||
results = await self.db.search_claims(channel="@some_channel")
|
results = await self.db.search_claims(channel="@some_channel")
|
||||||
self.assertEqual(len(results.rows), 0)
|
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
|
# direct resolves are still possible
|
||||||
result = await self.db.resolve([bad_content.permanent_url])
|
result = await self.db.resolve([bad_content.permanent_url])
|
||||||
self.assertEqual(bad_content.claim_id, result[bad_content.permanent_url].claim_id)
|
self.assertEqual(bad_content.claim_id, result[bad_content.permanent_url].claim_id)
|
||||||
|
|
Loading…
Add table
Reference in a new issue