fixup get_filtered from rebase

This commit is contained in:
Victor Shyba 2020-04-26 05:45:18 -03:00
parent 8a4fe4f3ad
commit 64c25b049c

View file

@ -95,21 +95,40 @@ class SourceManager:
raise ValueError(f"'{comparison}' is not a valid comparison") raise ValueError(f"'{comparison}' is not a valid comparison")
if 'full_status' in search_by: if 'full_status' in search_by:
del search_by['full_status'] del search_by['full_status']
for search in search_by: for search in search_by:
if search not in self.filter_fields: if search not in self.filter_fields:
raise ValueError(f"'{search}' is not a valid search operation") raise ValueError(f"'{search}' is not a valid search operation")
compare_sets = {}
if isinstance(search_by.get('claim_id'), list):
compare_sets['claim_ids'] = search_by.pop('claim_id')
if isinstance(search_by.get('outpoint'), list):
compare_sets['outpoints'] = search_by.pop('outpoint')
if isinstance(search_by.get('channel_claim_id'), list):
compare_sets['channel_claim_ids'] = search_by.pop('channel_claim_id')
if search_by: if search_by:
comparison = comparison or 'eq' comparison = comparison or 'eq'
sources = [] streams = []
for stream in self._sources.values(): for stream in self._sources.values():
matched = False
for set_search, val in compare_sets.items():
if COMPARISON_OPERATORS[comparison](getattr(stream, self.filter_fields[set_search]), val):
streams.append(stream)
matched = True
break
if matched:
continue
for search, val in search_by.items(): for search, val in search_by.items():
if COMPARISON_OPERATORS[comparison](getattr(stream, search), val): this_stream = getattr(stream, search)
sources.append(stream) if COMPARISON_OPERATORS[comparison](this_stream, val):
streams.append(stream)
break break
else: else:
sources = list(self._sources.values()) streams = list(self._sources.values())
if sort_by: if sort_by:
sources.sort(key=lambda s: getattr(s, sort_by)) streams.sort(key=lambda s: getattr(s, sort_by))
if reverse: if reverse:
sources.reverse() streams.reverse()
return sources return streams