config.cache_blocks_in_db default False

This commit is contained in:
tim
2024-08-31 20:12:29 -04:00
parent 16801b56ce
commit 18f22e2f09
2 changed files with 3 additions and 2 deletions

View File

@@ -37,7 +37,7 @@ class FetchLock:
async def _fetch(fetch: FetchLock, chain_id: int, block_id: Union[int,bytes]) -> Optional[Block]: async def _fetch(fetch: FetchLock, chain_id: int, block_id: Union[int,bytes]) -> Optional[Block]:
# try database first # try database first
if db: if config.cache_blocks_in_db and db:
chain = Blockchain.get(chain_id) chain = Blockchain.get(chain_id)
if type(block_id) is int: if type(block_id) is int:
# by-number could return multiple results # by-number could return multiple results
@@ -69,7 +69,7 @@ _fetch_locks:dict[tuple[int, bytes], FetchLock] = {}
def cache_block(block: Block, confirmed=False): def cache_block(block: Block, confirmed=False):
_lru[block.chain_id, block.hash] = block _lru[block.chain_id, block.hash] = block
_lru[block.chain_id, block.height] = block _lru[block.chain_id, block.height] = block
if db: if config.cache_blocks_in_db and db:
db.session.add(DbBlock( db.session.add(DbBlock(
chain=block.chain_id, hash=block.hash, height=block.height, timestamp=block.timestamp, chain=block.chain_id, hash=block.hash, height=block.height, timestamp=block.timestamp,
confirmed=confirmed, data=block.data)) confirmed=confirmed, data=block.data))

View File

@@ -18,6 +18,7 @@ class Config:
dump_sql: bool = False dump_sql: bool = False
redis_url: Optional[str] = 'redis://localhost:6379' redis_url: Optional[str] = 'redis://localhost:6379'
cache_blocks_in_db: bool = False
metadata: Optional[str] = None metadata: Optional[str] = None
ohlc_dir: Optional[str] = None # if empty string or None, then OHLC's are not saved to disk ohlc_dir: Optional[str] = None # if empty string or None, then OHLC's are not saved to disk
chunk_cache_size: int = 128 # Number of pools that have their OHLC chunks cached chunk_cache_size: int = 128 # Number of pools that have their OHLC chunks cached