-
Notifications
You must be signed in to change notification settings - Fork 16
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: refresh AI cache on proposal update #254
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files📢 Thoughts on this report? Let us know! |
throw new Error('RECORD_NOT_FOUND'); | ||
} | ||
if (!this.proposal) throw new Error('RECORD_NOT_FOUND'); | ||
if (this.#cacheExpired()) return false; |
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.
If cache is expired, isCacheable
should return true
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.
No, false
, since the item is not cache-able anymore
return tempCacheIds.has(id) && tempCacheIds.get(id) !== updated; | ||
}; | ||
|
||
afterCreateCache() { | ||
tempCacheIds.set(this.proposal!.id, this.proposal!.updated); | ||
} |
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 we can't relay on updated param for cache, a pending proposal can be updated any number of times
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.
The update
value will be cached only after cache creation. So each time it changes, it will invalidate the cache
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.
oh updated is timestamp. got it
Can you confirm it wouldnt cache AI summary if proposal is edited but no-one ask for AI summary? |
🧿 Current issues / What's wrong ?
AI summary and speech are cached for all proposals state (pending, active, closed).
Pending proposals can still be updated, and the AI cache is not refreshed after creation.
Closes #242
💊 Fixes / Solution
Refresh the AI cache on proposal update
🚧 Changes
🛠️ Tests
Test instructions are only for ai/TextToSpeech, and we're assuming that it will work for ai/Summary since it's getting the exact same changes.
Testing cache refresh from webhook
Goal:
Add/Set the following var in .env:
yarn dev
curl -X POST http://localhost:3005/api/ai/tts/0xcae036faf24a47a692748911c7d2701a7992d03585150ce63fc777bc590eb6ac
yarn dev
console the cache creation (storage:file] File saved to
). You can confirm the creation by checking that the filetmp/ai-tts-test/snapshot-proposal-ai-tts-0xcae036faf24a47a692748911c7d2701a7992d03585150ce63fc777bc590eb6ac.mp3
exist (from your project root). Give a little time for the item to appear in the console, as the queue is run every 3s.yarn dev
console should confirm that the cache is served ([storage:file] File fetched from
).curl --header "Content-Type: application/json" --header "Authentication: 0" --request POST --data '{"id":"proposal/0xcae036faf24a47a692748911c7d2701a7992d03585150ce63fc777bc590eb6ac","event":"proposal/start"}' http://localhost:3005/webhook
yarn dev
console, you should see the cache creation ([storage:file] File saved
), even though the cache already exist. This is because we refresh all existing cache on proposal start, to make sure.tmp/ai-tts-test/snapshot-proposal-ai-tts-0xcae036faf24a47a692748911c7d2701a7992d03585150ce63fc777bc590eb6ac.mp3
)Testing cache refresh for pending proposals
Goal:
yarn dev
curl -X POST http://localhost:3005/api/ai/tts/[YOUR_PROPOSAL_ID]
yarn dev
console, and that the file exist intmp/ai-tts-test/