return streams matching all file_list filters rather than those matching any

-fix filter fields when using sets
This commit is contained in:
Jack Robison 2020-05-11 18:43:47 -04:00
parent 78b8261a3a
commit a469b8bc04
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -37,6 +37,12 @@ class SourceManager:
'channel_name' 'channel_name'
} }
set_filter_fields = {
"claim_ids": "claim_id",
"channel_claim_ids": "channel_claim_id",
"outpoints": "outpoint"
}
source_class = ManagedDownloadSource source_class = ManagedDownloadSource
def __init__(self, loop: asyncio.AbstractEventLoop, config: 'Config', storage: 'SQLiteStorage', def __init__(self, loop: asyncio.AbstractEventLoop, config: 'Config', storage: 'SQLiteStorage',
@ -108,23 +114,19 @@ class SourceManager:
if isinstance(search_by.get('channel_claim_id'), list): if isinstance(search_by.get('channel_claim_id'), list):
compare_sets['channel_claim_ids'] = search_by.pop('channel_claim_id') compare_sets['channel_claim_ids'] = search_by.pop('channel_claim_id')
if search_by: if search_by or compare_sets:
comparison = comparison or 'eq' comparison = comparison or 'eq'
streams = [] streams = []
for stream in self._sources.values(): for stream in self._sources.values():
matched = False if compare_sets and not all(
for set_search, val in compare_sets.items(): getattr(stream, self.set_filter_fields[set_search]) in val
if COMPARISON_OPERATORS[comparison](getattr(stream, self.filter_fields[set_search]), val): for set_search, val in compare_sets.items()):
streams.append(stream)
matched = True
break
if matched:
continue continue
for search, val in search_by.items(): if search_by and not all(
this_stream = getattr(stream, search) COMPARISON_OPERATORS[comparison](getattr(stream, search), val)
if COMPARISON_OPERATORS[comparison](this_stream, val): for search, val in search_by.items()):
streams.append(stream) continue
break streams.append(stream)
else: else:
streams = list(self._sources.values()) streams = list(self._sources.values())
if sort_by: if sort_by: