feat(APP-1002): implement incremental caches for DAO addresses and token eligibility#1459
Open
harryburger wants to merge 2 commits into
Open
feat(APP-1002): implement incremental caches for DAO addresses and token eligibility#1459harryburger wants to merge 2 commits into
harryburger wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Implements incremental, in-memory caches for DAO addresses and token eligibility to reduce per-tick Mongo queries during log filtering in PoolingCrawler, improving throughput and scalability as log volume grows.
Changes:
- Added
DaoAddressCacheandTokenEligibilityCachewith per-network cursor-based refresh logic. - Refactored
PoolingCrawlerlog filtering to consult caches instead of running per-tickdistinct/$inDB queries. - Added unit tests for the new caches and added supporting
{ network, createdAt/updatedAt }indexes to schemas.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/unit/modules/tokenEligibilityCache.spec.ts | New unit tests for TokenEligibilityCache behavior (eligibility, revocation, delta refresh, concurrency). |
| test/unit/modules/poolingCrawler.spec.ts | Updates tests to account for cache-driven filtering and transfer handling behavior. |
| test/unit/modules/daoAddressCache.spec.ts | New unit tests for DaoAddressCache (initial load, delta refresh, isolation, dedupe, concurrency). |
| src/types/crawler.ts | Adds internal cache state interfaces used by the new cache modules. |
| src/modules/tokenEligibilityCache.ts | New incremental cache tracking eligible token addresses via Plugin/Token delta queries. |
| src/modules/poolingCrawler.ts | Refactors transfer + DelegateVotesChanged filtering to rely on the new caches. |
| src/modules/daoAddressCache.ts | New incremental cache tracking DAO addresses via createdAt delta queries. |
| src/models/schema/token.ts | Adds { network, updatedAt } index to support token eligibility delta queries. |
| src/models/schema/plugin.ts | Adds { network, updatedAt } index to support plugin eligibility delta queries. |
| src/models/schema/dao.ts | Adds { network, createdAt } index to support DAO address delta queries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+111
to
+125
| const eligible = await Models.Plugin.distinct('tokenAddress', { | ||
| ...pluginEligibility, | ||
| tokenAddress: { $in: [...changedAddresses] }, | ||
| network, | ||
| }) | ||
| const eligibleLower = new Set(eligible.map(address => address.toLowerCase())) | ||
|
|
||
| for (const address of changedAddresses) { | ||
| const lower = address.toLowerCase() | ||
| if (eligibleLower.has(lower)) { | ||
| state.pluginTokensByLower.set(lower, address) | ||
| } else { | ||
| state.pluginTokensByLower.delete(lower) | ||
| } | ||
| } |
Comment on lines
+160
to
+174
| const eligible = await Models.Token.distinct('address', { | ||
| ...tokenEligibility, | ||
| address: { $in: [...changedAddresses] }, | ||
| network, | ||
| }) | ||
| const eligibleLower = new Set(eligible.map(address => address.toLowerCase())) | ||
|
|
||
| for (const address of changedAddresses) { | ||
| const lower = address.toLowerCase() | ||
| if (eligibleLower.has(lower)) { | ||
| state.tokensByLower.set(lower, address) | ||
| } else { | ||
| state.tokensByLower.delete(lower) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎫 Linear
APP-1002
📝 Summary
This pull request introduces incremental, in-memory caches for DAO addresses and token eligibility, significantly optimizing log filtering in the
PoolingCrawlerby eliminating repeated database queries on every tick. The caches are kept up-to-date using efficient delta queries and are used to filter logs in a more performant and scalable way. The PR also includes new unit tests for the DAO address cache and adds supporting indexes to the schema.Caching and Query Optimization:
DaoAddressCacheandTokenEligibilityCachemodules, which maintain per-network, incremental, in-memory caches of DAO addresses and eligible token addresses, respectively. These caches use efficient delta queries to keep themselves up-to-date and replace repeated$in/distinctDB queries during log filtering. (src/modules/daoAddressCache.ts[1]src/modules/tokenEligibilityCache.ts[2]PoolingCrawlerto use these caches for DAO and token eligibility checks, removing per-tick DB queries and custom deduplication logic. (src/modules/poolingCrawler.ts[1] [2] [3] [4] [5]Schema and Indexing:
{ network, createdAt }for DAOs,{ network, updatedAt }for Plugins and Tokens to support efficient incremental queries for the caches. (src/models/schema/dao.ts[1]src/models/schema/plugin.ts[2]src/models/schema/token.ts[3]Types and Interfaces:
INetworkCacheStateandITokenEligibilityCacheStateto describe the internal state of the caches. (src/types/crawler.tssrc/types/crawler.tsR193-R221)Testing:
test/unit/modules/daoAddressCache.spec.tstest/unit/modules/daoAddressCache.spec.tsR1-R99)✅ Checklist
🔍 Code Review
🧪 Testing
🔒 Security