-
Notifications
You must be signed in to change notification settings - Fork 35
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
refactor: extract cache logic from getVp
#938
base: master
Are you sure you want to change the base?
Conversation
src/methods.ts
Outdated
return await cachedVp( | ||
sha256(JSON.stringify(params)), | ||
async () => { | ||
return await snapshot.utils.getVp( | ||
params.address, | ||
params.network, | ||
params.strategies, | ||
params.snapshot, | ||
params.space, | ||
params.delegation | ||
); | ||
}, | ||
params.snapshot !== 'latest' && !disableCachingForSpaces.includes(params.space) |
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 have never seen our team using callbacks 🙈 especially less
should that be fine?
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.
It's the most elegant way to do this thing.
We use it in the requestDeduplicator
getVp
getVp
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #938 +/- ##
==========================================
+ Coverage 72.33% 75.97% +3.64%
==========================================
Files 13 14 +1
Lines 665 691 +26
Branches 106 116 +10
==========================================
+ Hits 481 525 +44
+ Misses 180 163 -17
+ Partials 4 3 -1 ☔ View full report in Codecov by Sentry. |
🧿 Current issues / What's wrong ?
The cache engine is tightly coupled to the
getVp
function, making it harder to test and adding too much unrelated lines unrelated to the core function (almost half of the function's lines are related to cache set and get)💊 Fixes / Solution
Extract the cache function from the
getVp
function.The goal here is:
getVp
function by removing the cache logicgetScores
to this cache engine in later PR, to benefit from instrumentation🚧 Changes
🛠️ Tests
yarn dev
cache: false
on first runcache: true
on subsequent run