예제 #1
0
파일: search.py 프로젝트: belikor/lbry-sdk
 async def session_query(self, query_name, kwargs):
     offset, total = kwargs.get('offset', 0) if isinstance(kwargs, dict) else 0, 0
     total_referenced = []
     if query_name == 'resolve':
         total_referenced, response, censor = await self.resolve(*kwargs)
     else:
         cache_item = ResultCacheItem.from_cache(str(kwargs), self.search_cache)
         if cache_item.result is not None:
             return cache_item.result
         async with cache_item.lock:
             if cache_item.result:
                 return cache_item.result
             censor = Censor(Censor.SEARCH)
             if kwargs.get('no_totals'):
                 response, offset, total = await self.search(**kwargs, censor_type=Censor.NOT_CENSORED)
             else:
                 response, offset, total = await self.search(**kwargs)
             censor.apply(response)
             total_referenced.extend(response)
             if censor.censored:
                 response, _, _ = await self.search(**kwargs, censor_type=Censor.NOT_CENSORED)
                 total_referenced.extend(response)
             result = Outputs.to_base64(
                 response, await self._get_referenced_rows(total_referenced), offset, total, censor
             )
             cache_item.result = result
             return result
     return Outputs.to_base64(response, await self._get_referenced_rows(total_referenced), offset, total, censor)
예제 #2
0
    async def resolve(self, *urls):
        censor = Censor(Censor.RESOLVE)
        results = [await self.resolve_url(url) for url in urls]
        # just heat the cache
        await self.populate_claim_cache(*filter(lambda x: isinstance(x, str), results))
        results = [self._get_from_cache_or_error(url, result) for url, result in zip(urls, results)]

        censored = [
            result if not isinstance(result, dict) or not censor.censor(result)
            else ResolveCensoredError(url, result['censoring_channel_hash'])
            for url, result in zip(urls, results)
        ]
        return results, censored, censor
예제 #3
0
파일: reader.py 프로젝트: zhyniq/lbry-sdk
def count_claims(**constraints) -> int:
    constraints.pop('offset', None)
    constraints.pop('limit', None)
    constraints.pop('order_by', None)
    count = select_claims(Censor(),
                          'count(*) as row_count',
                          for_count=True,
                          **constraints)
    return count[0]['row_count']
예제 #4
0
 def get_search_censor(self, limit_claims_per_channel: int) -> Censor:
     return Censor(self.filtered_streams, self.filtered_channels, limit_claims_per_channel)
예제 #5
0
 def get_resolve_censor(self) -> Censor:
     return Censor(self.blocked_streams, self.blocked_channels)
예제 #6
0
파일: search.py 프로젝트: nishp77/lbry-sdk
    async def cached_search(self, kwargs):
        total_referenced = []
        cache_item = ResultCacheItem.from_cache(str(kwargs), self.search_cache)
        if cache_item.result is not None:
            return cache_item.result
        async with cache_item.lock:
            if cache_item.result:
                return cache_item.result
            censor = Censor(Censor.SEARCH)
            if kwargs.get('no_totals'):
                response, offset, total = await self.search(
                    **kwargs, censor_type=Censor.NOT_CENSORED)
            else:
                response, offset, total = await self.search(**kwargs)
            censor.apply(response)
            total_referenced.extend(response)

            if censor.censored:
                response, _, _ = await self.search(
                    **kwargs, censor_type=Censor.NOT_CENSORED)
                total_referenced.extend(response)
            response = [
                ResolveResult(name=r['claim_name'],
                              normalized_name=r['normalized_name'],
                              claim_hash=r['claim_hash'],
                              tx_num=r['tx_num'],
                              position=r['tx_nout'],
                              tx_hash=r['tx_hash'],
                              height=r['height'],
                              amount=r['amount'],
                              short_url=r['short_url'],
                              is_controlling=r['is_controlling'],
                              canonical_url=r['canonical_url'],
                              creation_height=r['creation_height'],
                              activation_height=r['activation_height'],
                              expiration_height=r['expiration_height'],
                              effective_amount=r['effective_amount'],
                              support_amount=r['support_amount'],
                              last_takeover_height=r['last_take_over_height'],
                              claims_in_channel=r['claims_in_channel'],
                              channel_hash=r['channel_hash'],
                              reposted_claim_hash=r['reposted_claim_hash'],
                              reposted=r['reposted'],
                              signature_valid=r['signature_valid'])
                for r in response
            ]
            extra = [
                ResolveResult(name=r['claim_name'],
                              normalized_name=r['normalized_name'],
                              claim_hash=r['claim_hash'],
                              tx_num=r['tx_num'],
                              position=r['tx_nout'],
                              tx_hash=r['tx_hash'],
                              height=r['height'],
                              amount=r['amount'],
                              short_url=r['short_url'],
                              is_controlling=r['is_controlling'],
                              canonical_url=r['canonical_url'],
                              creation_height=r['creation_height'],
                              activation_height=r['activation_height'],
                              expiration_height=r['expiration_height'],
                              effective_amount=r['effective_amount'],
                              support_amount=r['support_amount'],
                              last_takeover_height=r['last_take_over_height'],
                              claims_in_channel=r['claims_in_channel'],
                              channel_hash=r['channel_hash'],
                              reposted_claim_hash=r['reposted_claim_hash'],
                              reposted=r['reposted'],
                              signature_valid=r['signature_valid'])
                for r in await self._get_referenced_rows(total_referenced)
            ]
            result = Outputs.to_base64(response, extra, offset, total, censor)
            cache_item.result = result
            return result
예제 #7
0
 def get_search_censor(self) -> Censor:
     return Censor(self.filtered_streams, self.filtered_channels)
예제 #8
0
 def get_search_censor(self, limit_claims_per_channel: int) -> Censor:
     return Censor(Censor.SEARCH)
예제 #9
0
 def get_resolve_censor(self) -> Censor:
     return Censor(Censor.RESOLVE)
예제 #10
0
def search(**constraints) -> List:
    return reader.search_claims(Censor(Censor.SEARCH), **constraints)