check for information_schema.table_constraint instead of filters

This commit is contained in:
Victor Shyba 2020-12-18 16:27:56 -03:00 committed by Lex Berezhny
parent e65e49768a
commit 546205ba69
2 changed files with 11 additions and 1 deletions

View file

@ -165,6 +165,8 @@ def claims_insert(
@event_emitter("blockchain.sync.claims.indexes", "steps")
def claims_constraints_and_indexes(p: ProgressContext):
if p.ctx.is_postgres and pg_has_claim_primary_key(p):
return
p.start(2 + len(pg_add_claim_and_tag_constraints_and_indexes))
if p.ctx.is_postgres:
p.ctx.execute_notx(text("VACUUM ANALYZE claim;"))
@ -309,3 +311,11 @@ def update_claim_filters(resolve_censor_channel_hashes, search_censor_channel_ha
['claim_hash', 'censor_type', 'censoring_channel_hash'],
select_reposts(search_censor_channel_hashes, Censor.SEARCH)
))
def pg_has_claim_primary_key(p: ProgressContext):
claim_constraints = p.ctx.execute(
"select * from information_schema.table_constraints as tc "
"where tc.table_name='claim' and constraint_type='PRIMARY KEY'"
).fetchall()
return len(claim_constraints) > 0

View file

@ -259,7 +259,7 @@ class BlockchainSync(Sync):
async def sync_claims(self, blocks) -> bool:
delete_claims = takeovers = claims_with_changed_supports = claims_with_changed_reposts = 0
initial_sync = not await self.db.has_filters()
initial_sync = not await self.db.has_claims()
with Progress(self.db.message_queue, CLAIMS_INIT_EVENT) as p:
if initial_sync:
total, batches = await self.distribute_unspent_txos(CLAIM_TYPE_CODES)