forked from LBRYCommunity/lbry-sdk
clean up claim producer
This commit is contained in:
parent
32b26c9fa5
commit
e0f7066163
1 changed files with 42 additions and 30 deletions
|
@ -165,27 +165,29 @@ class ElasticWriter(BlockchainReader):
|
||||||
self.index, body=self.update_filter_query(Censor.RESOLVE, blocked_channels, True), slices=4)
|
self.index, body=self.update_filter_query(Censor.RESOLVE, blocked_channels, True), slices=4)
|
||||||
await self.sync_client.indices.refresh(self.index)
|
await self.sync_client.indices.refresh(self.index)
|
||||||
|
|
||||||
async def _claim_producer(self):
|
@staticmethod
|
||||||
for deleted in self._deleted_claims:
|
def _upsert_claim_query(index, claim):
|
||||||
yield {
|
return {
|
||||||
'_index': self.index,
|
|
||||||
'_op_type': 'delete',
|
|
||||||
'_id': deleted.hex()
|
|
||||||
}
|
|
||||||
for touched in self._touched_claims:
|
|
||||||
claim = self.db.claim_producer(touched)
|
|
||||||
if claim:
|
|
||||||
yield {
|
|
||||||
'doc': {key: value for key, value in claim.items() if key in ALL_FIELDS},
|
'doc': {key: value for key, value in claim.items() if key in ALL_FIELDS},
|
||||||
'_id': claim['claim_id'],
|
'_id': claim['claim_id'],
|
||||||
'_index': self.index,
|
'_index': index,
|
||||||
'_op_type': 'update',
|
'_op_type': 'update',
|
||||||
'doc_as_upsert': True
|
'doc_as_upsert': True
|
||||||
}
|
}
|
||||||
for claim_hash, notifications in self._trending.items():
|
|
||||||
yield {
|
@staticmethod
|
||||||
|
def _delete_claim_query(index, claim_hash: bytes):
|
||||||
|
return {
|
||||||
|
'_index': index,
|
||||||
|
'_op_type': 'delete',
|
||||||
|
'_id': claim_hash.hex()
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _update_trending_query(index, claim_hash, notifications):
|
||||||
|
return {
|
||||||
'_id': claim_hash.hex(),
|
'_id': claim_hash.hex(),
|
||||||
'_index': self.index,
|
'_index': index,
|
||||||
'_op_type': 'update',
|
'_op_type': 'update',
|
||||||
'script': {
|
'script': {
|
||||||
'lang': 'painless',
|
'lang': 'painless',
|
||||||
|
@ -202,6 +204,16 @@ class ElasticWriter(BlockchainReader):
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async def _claim_producer(self):
|
||||||
|
for deleted in self._deleted_claims:
|
||||||
|
yield self._delete_claim_query(self.index, deleted)
|
||||||
|
for touched in self._touched_claims:
|
||||||
|
claim = self.db.claim_producer(touched)
|
||||||
|
if claim:
|
||||||
|
yield self._upsert_claim_query(self.index, claim)
|
||||||
|
for claim_hash, notifications in self._trending.items():
|
||||||
|
yield self._update_trending_query(self.index, claim_hash, notifications)
|
||||||
|
|
||||||
def advance(self, height: int):
|
def advance(self, height: int):
|
||||||
super().advance(height)
|
super().advance(height)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue