mirror of
https://github.com/LBRYFoundation/lbry-sdk.git
synced 2025-08-29 16:31:25 +00:00
delete claims above reorg height from the database
This commit is contained in:
parent
130d36acd9
commit
64f7f837e7
2 changed files with 13 additions and 3 deletions
|
@ -2,7 +2,7 @@ import time
|
||||||
import asyncio
|
import asyncio
|
||||||
from struct import pack, unpack
|
from struct import pack, unpack
|
||||||
from concurrent.futures.thread import ThreadPoolExecutor
|
from concurrent.futures.thread import ThreadPoolExecutor
|
||||||
|
from typing import Optional
|
||||||
import lbry
|
import lbry
|
||||||
from lbry.schema.claim import Claim
|
from lbry.schema.claim import Claim
|
||||||
from lbry.wallet.server.db.writer import SQLDB
|
from lbry.wallet.server.db.writer import SQLDB
|
||||||
|
@ -219,7 +219,7 @@ class BlockProcessor:
|
||||||
'resetting the prefetcher')
|
'resetting the prefetcher')
|
||||||
await self.prefetcher.reset_height(self.height)
|
await self.prefetcher.reset_height(self.height)
|
||||||
|
|
||||||
async def reorg_chain(self, count=None):
|
async def reorg_chain(self, count: Optional[int] = None):
|
||||||
"""Handle a chain reorganisation.
|
"""Handle a chain reorganisation.
|
||||||
|
|
||||||
Count is the number of blocks to simulate a reorg, or None for
|
Count is the number of blocks to simulate a reorg, or None for
|
||||||
|
@ -253,6 +253,7 @@ class BlockProcessor:
|
||||||
await self.run_in_thread_with_lock(self.backup_blocks, raw_blocks)
|
await self.run_in_thread_with_lock(self.backup_blocks, raw_blocks)
|
||||||
await self.run_in_thread_with_lock(flush_backup)
|
await self.run_in_thread_with_lock(flush_backup)
|
||||||
last -= len(raw_blocks)
|
last -= len(raw_blocks)
|
||||||
|
self.db.sql.delete_claims_above_height(self.height)
|
||||||
await self.prefetcher.reset_height(self.height)
|
await self.prefetcher.reset_height(self.height)
|
||||||
|
|
||||||
async def reorg_hashes(self, count):
|
async def reorg_hashes(self, count):
|
||||||
|
@ -270,7 +271,7 @@ class BlockProcessor:
|
||||||
|
|
||||||
return start, last, await self.db.fs_block_hashes(start, count)
|
return start, last, await self.db.fs_block_hashes(start, count)
|
||||||
|
|
||||||
async def calc_reorg_range(self, count):
|
async def calc_reorg_range(self, count: Optional[int]):
|
||||||
"""Calculate the reorg range"""
|
"""Calculate the reorg range"""
|
||||||
|
|
||||||
def diff_pos(hashes1, hashes2):
|
def diff_pos(hashes1, hashes2):
|
||||||
|
|
|
@ -433,6 +433,15 @@ class SQLDB:
|
||||||
return {r.channel_hash for r in affected_channels}
|
return {r.channel_hash for r in affected_channels}
|
||||||
return set()
|
return set()
|
||||||
|
|
||||||
|
def delete_claims_above_height(self, height: int):
|
||||||
|
claim_hashes = [x[0] for x in self.execute(
|
||||||
|
"SELECT claim_hash FROM claim WHERE height>=?", (height, )
|
||||||
|
).fetchall()]
|
||||||
|
while claim_hashes:
|
||||||
|
batch = set(claim_hashes[:500])
|
||||||
|
claim_hashes = claim_hashes[500:]
|
||||||
|
self.delete_claims(batch)
|
||||||
|
|
||||||
def _clear_claim_metadata(self, claim_hashes: Set[bytes]):
|
def _clear_claim_metadata(self, claim_hashes: Set[bytes]):
|
||||||
if claim_hashes:
|
if claim_hashes:
|
||||||
for table in ('tag',): # 'language', 'location', etc
|
for table in ('tag',): # 'language', 'location', etc
|
||||||
|
|
Loading…
Add table
Reference in a new issue