config.cache_blocks_in_db default False
This commit is contained in:
@@ -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))
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user