New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added ape cache plugin #680
feat: added ape cache plugin #680
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coming along!
My main two comments:
- Avoid string interpolation in SQL - use query parameters instead... It is better practice and has more security checks
- What happened to
DefaultQueryProvider
? Are we required to have a DB now? This would be a pretty big breaking change, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the docs in ape_cache
can just be deleted! We don't really generate anything from those.
Address @fubuloubu 's thing and make the tests happy and it is an approval from me :)
Bonus if you use the logger though! It is better because I sometimes like to disable output using the --verbosity
flag and it's more consistent.
Thank you :)
Should we force the query to pull all data from the provider if it doesn't exist? That way we could populate the cache db. If you wanted to only see the |
By default, it already is pulling all the data, however it is then filtering out all the data that wasn't asked for. So pushing that data to the cache db prior to that filter being applied would be an acceptable way to proceed. Since it's an iterator, you would need |
Not sure how to handle this issue. This this is a quick fix that I'm not seeing, let me know |
Sounds like your environment is behind? Try fetching the latest version of ape core from upstream and see if that fixes it. |
yeah, it is, I'm up to date with the main, rebased, yet when I install, it still installs 0.1... not sure why. I'll remake my venv |
3825829
to
2fd5b78
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some small code optimizations.
I have an idea for some tests, but it might not be easy:
- Populate the
.db
files on your machine for various providers. - Add those files to test fixtures and use them in tests
And so that leads to me another idea: Allow connecting to HistoricalProvider
which only requires the .db
files and no active connection. This will help with testing against historical data.
Edit: the testing / historical-provider design can happen later, but tests would be nice somehow.
Only issue left is I cannot store the data as is. We get an error for unsupported types. |
64833a3
to
275a960
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of my other comments were resolved though I don't see the resolution (maybe not pushed yet?).
Looking fantastic though! I can't wait to use, especially for mainnet-fork
.
I want to make a pre-populated mainnet-fork
.db for testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little bit more refactoring and we can merge this!
Then move optimization work to another PR (partial row support, mgirations, etc.)
ac71cd4
to
348e5ee
Compare
eeadc53
to
faadc8c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Minimally, go to |
@fubuloubu I respectfully argue against using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one major refactor and a bunch of minor comments, and we are good
src/ape_cache/query.py
Outdated
) | ||
|
||
@singledispatchmethod | ||
def perform_query(self, query: QueryType) -> Optional[Iterator]: # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def perform_query(self, query: QueryType) -> Optional[Iterator]: # type: ignore | |
def perform_query(self, query: QueryType) -> Iterator: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need the type ignore. Without it I get:
src/ape_cache/query.py:314: error: Signature of "perform_query" incompatible with supertype "QueryAPI"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm
@fubuloubu I'm not touching that Squash and Merge button! Too much pressure! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, with many issues coming out of this which @NotPeopling2day is tracking
6c79a10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I did
Added CacheQueryProvider to ape cache and created initial database structure and methods to instantiate an sqlite database for caching provider data.
fixes: #632
How I did it
created cli and added init, purge and query functions
How to verify it
I used the infura plugin
Then instantiate the caching database
Run this multiple times:
You should see that the query occurs quicker after the first call. This will take a few seconds to grab the data from the provider
Also run transaction calls multiple times:
You should see that the query is quicker after the first call. That block number can change, so you may not see it after the first attempt. But you will have
DynamicTransactionAPI
datatypes in the return if it comes from the provider. You will just receive a dictionary if it comes from the database.Then exit the IPython kernel
And run the below commands
Both should return data from the database.
Also run pytests
Checklist