fix interaction between two modes

This commit is contained in:
Victor Shyba 2021-05-20 01:20:25 -03:00
parent 4870974161
commit 3974df4a62
2 changed files with 6 additions and 2 deletions

View file

@ -287,7 +287,7 @@ class SearchIndex:
result = list(await self.get_many(*(claim_id for claim_id, _ in reordered_hits[offset:(offset + page_size)]))) result = list(await self.get_many(*(claim_id for claim_id, _ in reordered_hits[offset:(offset + page_size)])))
return result, 0, len(reordered_hits) return result, 0, len(reordered_hits)
def __remove_duplicates(self, search_hits: list): def __remove_duplicates(self, search_hits: deque) -> deque:
known_ids = {} # claim_id -> (creation_height, hit_id), where hit_id is either reposted claim id or original known_ids = {} # claim_id -> (creation_height, hit_id), where hit_id is either reposted claim id or original
dropped = set() dropped = set()
for hit in search_hits: for hit in search_hits:
@ -301,7 +301,7 @@ class SearchIndex:
dropped.add(previous_id) dropped.add(previous_id)
else: else:
dropped.add(hit['_id']) dropped.add(hit['_id'])
return [hit for hit in search_hits if hit['_id'] not in dropped] return deque(hit for hit in search_hits if hit['_id'] not in dropped)
def __search_ahead(self, search_hits: list, page_size: int, per_channel_per_page: int): def __search_ahead(self, search_hits: list, page_size: int, per_channel_per_page: int):
reordered_hits = [] reordered_hits = []

View file

@ -419,6 +419,10 @@ class ClaimSearchCommand(ClaimTestCase):
await match([channels[0], claims[0], channels[1], claims[1]] + channels[2:], await match([channels[0], claims[0], channels[1], claims[1]] + channels[2:],
height='>218', height='>218',
remove_duplicates=True, order_by=['^height']) remove_duplicates=True, order_by=['^height'])
# limit claims per channel, invert order, oldest ones are still chosen
await match(channels[2:][::-1] + [claims[1], channels[1], claims[0], channels[0]],
height='>218', limit_claims_per_channel=1,
remove_duplicates=True, order_by=['height'])
async def test_limit_claims_per_channel_across_sorted_pages(self): async def test_limit_claims_per_channel_across_sorted_pages(self):
await self.generate(10) await self.generate(10)