Skip to content

feat(APP-1002): implement incremental caches for DAO addresses and token eligibility#1459

Open
harryburger wants to merge 2 commits into
developmentfrom
perf/incremental-address-caches-pooling-filter
Open

feat(APP-1002): implement incremental caches for DAO addresses and token eligibility#1459
harryburger wants to merge 2 commits into
developmentfrom
perf/incremental-address-caches-pooling-filter

Conversation

@harryburger

@harryburger harryburger commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

🎫 Linear

APP-1002

📝 Summary

This pull request introduces incremental, in-memory caches for DAO addresses and token eligibility, significantly optimizing log filtering in the PoolingCrawler by 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:

  • Introduced DaoAddressCache and TokenEligibilityCache modules, 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/distinct DB queries during log filtering. (src/modules/daoAddressCache.ts [1] src/modules/tokenEligibilityCache.ts [2]
  • Refactored PoolingCrawler to 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:

  • Added new compound indexes on { 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:

  • Added new TypeScript interfaces INetworkCacheState and ITokenEligibilityCacheState to describe the internal state of the caches. (src/types/crawler.ts src/types/crawler.tsR193-R221)

Testing:

  • Added comprehensive unit tests for the DAO address cache, covering initial load, delta refresh, network isolation, deduplication, and concurrency. (test/unit/modules/daoAddressCache.spec.ts test/unit/modules/daoAddressCache.spec.tsR1-R99)

✅ Checklist

🔍 Code Review

  • Self-reviewed all code changes
  • Ask AI/Copilot code review
  • Removed all debug code, console.logs, and dead code
  • Implemented error handling with try/catch blocks where needed

🧪 Testing

  • All test suites pass locally
  • Added comprehensive unit tests for new features
  • Included integration tests for end-to-end scenarios
  • Successfully tested on remote server

🔒 Security

  • Verified no secrets or credentials are exposed
  • Reviewed for common security vulnerabilities
  • Verified commit authorship - Reviewed all commits to ensure they're from team members (check for compromised accounts)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DaoAddressCache and TokenEligibilityCache with per-network cursor-based refresh logic.
  • Refactored PoolingCrawler log filtering to consult caches instead of running per-tick distinct/$in DB 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)
}
}
@linear-code

linear-code Bot commented Jul 17, 2026

Copy link
Copy Markdown

APP-1002

@harryburger harryburger changed the title feat(caching): implement incremental caches for DAO addresses and token eligibility feat(APP-1002): implement incremental caches for DAO addresses and token eligibility Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants