From 3974df4a62765f36940682d8ec3dad287c0cfd4b Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Thu, 20 May 2021 01:20:25 -0300 Subject: [PATCH] fix interaction between two modes --- lbry/wallet/server/db/elasticsearch/search.py | 4 ++-- tests/integration/blockchain/test_claim_commands.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lbry/wallet/server/db/elasticsearch/search.py b/lbry/wallet/server/db/elasticsearch/search.py index c562ec684..3b98999b5 100644 --- a/lbry/wallet/server/db/elasticsearch/search.py +++ b/lbry/wallet/server/db/elasticsearch/search.py @@ -287,7 +287,7 @@ class SearchIndex: result = list(await self.get_many(*(claim_id for claim_id, _ in reordered_hits[offset:(offset + page_size)]))) 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 dropped = set() for hit in search_hits: @@ -301,7 +301,7 @@ class SearchIndex: dropped.add(previous_id) else: 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): reordered_hits = [] diff --git a/tests/integration/blockchain/test_claim_commands.py b/tests/integration/blockchain/test_claim_commands.py index 488926c76..c7c134cb6 100644 --- a/tests/integration/blockchain/test_claim_commands.py +++ b/tests/integration/blockchain/test_claim_commands.py @@ -419,6 +419,10 @@ class ClaimSearchCommand(ClaimTestCase): await match([channels[0], claims[0], channels[1], claims[1]] + channels[2:], height='>218', 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): await self.generate(10)