refactor level to get_xyz_...
This commit is contained in:
parent
4e0728572d
commit
e4449d2ec7
3 changed files with 14 additions and 13 deletions
|
@ -18,7 +18,7 @@ log = logging.getLogger(__name__)
|
|||
def resolve_claims(**constraints):
|
||||
censor = context().get_resolve_censor()
|
||||
rows = context().fetchall(select_claims(**constraints))
|
||||
rows = censor.apply(rows, level=2)
|
||||
rows = censor.apply(rows)
|
||||
return rows_to_txos(rows), censor
|
||||
|
||||
|
||||
|
|
|
@ -85,11 +85,13 @@ class QueryContext:
|
|||
def raise_unsupported_dialect(self):
|
||||
raise RuntimeError(f'Unsupported database dialect: {self.engine.dialect.name}.')
|
||||
|
||||
def get_resolve_censor(self) -> Censor:
|
||||
return Censor(self.blocked_streams, self.blocked_channels)
|
||||
@classmethod
|
||||
def get_resolve_censor(cls) -> Censor:
|
||||
return Censor(level=2)
|
||||
|
||||
def get_search_censor(self) -> Censor:
|
||||
return Censor(self.filtered_streams, self.filtered_channels)
|
||||
@classmethod
|
||||
def get_search_censor(cls) -> Censor:
|
||||
return Censor(level=1)
|
||||
|
||||
def pg_copy(self, table, rows):
|
||||
with self.engine.begin() as c:
|
||||
|
|
|
@ -24,19 +24,18 @@ def set_reference(reference, claim_hash, rows):
|
|||
|
||||
class Censor:
|
||||
|
||||
__slots__ = 'streams', 'channels', 'censored', 'total'
|
||||
__slots__ = 'level', 'censored', 'total'
|
||||
|
||||
def __init__(self, streams: dict = None, channels: dict = None):
|
||||
self.streams = streams or {}
|
||||
self.channels = channels or {}
|
||||
def __init__(self, level=1):
|
||||
self.level = level
|
||||
self.censored = {}
|
||||
self.total = 0
|
||||
|
||||
def apply(self, rows, level=1):
|
||||
return [row for row in rows if not self.censor(row, level)]
|
||||
def apply(self, rows):
|
||||
return [row for row in rows if not self.censor(row)]
|
||||
|
||||
def censor(self, row, level=1) -> bool:
|
||||
was_censored = row['censor_type'] >= level
|
||||
def censor(self, row) -> bool:
|
||||
was_censored = row['censor_type'] >= self.level
|
||||
if was_censored:
|
||||
censoring_channel_hash = row['censor_owner_hash']
|
||||
self.censored.setdefault(censoring_channel_hash, 0)
|
||||
|
|
Loading…
Add table
Reference in a new issue