check for information_schema.table_constraint instead of filters
This commit is contained in:
parent
e65e49768a
commit
546205ba69
2 changed files with 11 additions and 1 deletions
|
@ -165,6 +165,8 @@ def claims_insert(
|
||||||
|
|
||||||
@event_emitter("blockchain.sync.claims.indexes", "steps")
|
@event_emitter("blockchain.sync.claims.indexes", "steps")
|
||||||
def claims_constraints_and_indexes(p: ProgressContext):
|
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))
|
p.start(2 + len(pg_add_claim_and_tag_constraints_and_indexes))
|
||||||
if p.ctx.is_postgres:
|
if p.ctx.is_postgres:
|
||||||
p.ctx.execute_notx(text("VACUUM ANALYZE claim;"))
|
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'],
|
['claim_hash', 'censor_type', 'censoring_channel_hash'],
|
||||||
select_reposts(search_censor_channel_hashes, Censor.SEARCH)
|
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
|
||||||
|
|
|
@ -259,7 +259,7 @@ class BlockchainSync(Sync):
|
||||||
|
|
||||||
async def sync_claims(self, blocks) -> bool:
|
async def sync_claims(self, blocks) -> bool:
|
||||||
delete_claims = takeovers = claims_with_changed_supports = claims_with_changed_reposts = 0
|
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:
|
with Progress(self.db.message_queue, CLAIMS_INIT_EVENT) as p:
|
||||||
if initial_sync:
|
if initial_sync:
|
||||||
total, batches = await self.distribute_unspent_txos(CLAIM_TYPE_CODES)
|
total, batches = await self.distribute_unspent_txos(CLAIM_TYPE_CODES)
|
||||||
|
|
Loading…
Add table
Reference in a new issue