Skip to content

Commit

Permalink
feat: simplified logic in estimate_block_query
Browse files Browse the repository at this point in the history
  • Loading branch information
johnson2427 committed May 12, 2022
1 parent 60c54e1 commit 348e5ee
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/ape_cache/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,17 @@ def estimate_block_query(self, query: BlockQuery) -> Optional[int]:
stop_block=query.stop_block,
step=query.step,
)
number_of_rows = q.rowcount
if q.rowcount < query.stop_block - query.start_block:
return None

except Exception as err:
# Note: If any error, skip the data from the cache and continue to
# query from provider.
logger.debug(err)
number_of_rows = 0
return None

# NOTE: Assume 200 msec to get data from database
time_to_get_cached_records = 200 if number_of_rows > 0 else None
# NOTE: Very loose estimate of 0.75ms per block
return time_to_get_cached_records
return 200

@singledispatchmethod
def perform_query(self, query: QueryType) -> pd.DataFrame: # type: ignore
Expand Down

0 comments on commit 348e5ee

Please sign in to comment.