From 18f22e2f09a2ffc586c5173b7d0a62d886274d45 Mon Sep 17 00:00:00 2001 From: tim Date: Sat, 31 Aug 2024 20:12:29 -0400 Subject: [PATCH] config.cache_blocks_in_db default False --- src/dexorder/blocks.py | 4 ++-- src/dexorder/configuration/schema.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/dexorder/blocks.py b/src/dexorder/blocks.py index 7c416d1..6cd228a 100644 --- a/src/dexorder/blocks.py +++ b/src/dexorder/blocks.py @@ -37,7 +37,7 @@ class FetchLock: async def _fetch(fetch: FetchLock, chain_id: int, block_id: Union[int,bytes]) -> Optional[Block]: # try database first - if db: + if config.cache_blocks_in_db and db: chain = Blockchain.get(chain_id) if type(block_id) is int: # by-number could return multiple results @@ -69,7 +69,7 @@ _fetch_locks:dict[tuple[int, bytes], FetchLock] = {} def cache_block(block: Block, confirmed=False): _lru[block.chain_id, block.hash] = block _lru[block.chain_id, block.height] = block - if db: + if config.cache_blocks_in_db and db: db.session.add(DbBlock( chain=block.chain_id, hash=block.hash, height=block.height, timestamp=block.timestamp, confirmed=confirmed, data=block.data)) diff --git a/src/dexorder/configuration/schema.py b/src/dexorder/configuration/schema.py index 265b342..fc56f3f 100644 --- a/src/dexorder/configuration/schema.py +++ b/src/dexorder/configuration/schema.py @@ -18,6 +18,7 @@ class Config: dump_sql: bool = False redis_url: Optional[str] = 'redis://localhost:6379' + cache_blocks_in_db: bool = False metadata: Optional[str] = None 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