Skip to content

Feat/batch operations#130

Merged
LeonardoVieira1630 merged 26 commits into
devfrom
feat/batch-operations
Sep 3, 2025
Merged

Feat/batch operations#130
LeonardoVieira1630 merged 26 commits into
devfrom
feat/batch-operations

Conversation

@LeonardoVieira1630
Copy link
Copy Markdown
Member

@LeonardoVieira1630 LeonardoVieira1630 commented Aug 28, 2025

Summary

This PR introduces batch processing capabilities across the notification system to significantly improve performance by reducing N+1 query patterns and optimizing API calls.

Changes Made

🎯 Subscription Server

  • New batch endpoint: POST /users/by-addresses/batch for fetching users by multiple wallet addresses in a single request
  • Enhanced service layer: Added getUsersByWalletAddressesBatch() method with optimized database queries
  • Repository improvements: Added findByAddresses() and findByIds() methods for efficient batch operations

🚀 Dispatcher Service

  • Batch client methods: Added getWalletOwnersBatch() and shouldSendBatch() to SubscriptionClient
  • Interface updates: Extended ISubscriptionClient with batch operation signatures
  • VotingPowerTrigger optimization: Eliminated N+1 API calls by batching wallet owner lookups and DAO subscriber queries

🧪 Testing

  • Enhanced test coverage: Added mocks for all new batch methods
  • Updated test suites: Modified existing tests to include new batch operation mocks

Performance Impact

Before

  • VotingPowerTrigger made individual API calls for each wallet address
  • Multiple sequential database queries for user lookups
  • Linear scaling with number of addresses

After

  • Single batch API call handles multiple wallet addresses
  • Optimized database queries with joins and batch operations
  • Constant time complexity for batch operations

Test Plan

  • All existing tests pass (43/43)
  • New batch endpoints tested with various scenarios
  • Performance verification shows significant improvement in multi-address operations
  • TypeScript compilation successful across all packages

Breaking Changes

None - all new functionality is additive and maintains backward compatibility.

Dependencies

No new external dependencies added. Uses existing infrastructure.

LeonardoVieira1630 and others added 5 commits August 28, 2025 09:56
- Add getUsersByWalletAddressesBatch method in SubscriptionService
- Add findByIds and findByAddresses methods in KnexUserRepository
- Add findByAddresses method in KnexUserAddressRepository
- Add POST /users/by-addresses/batch endpoint in UserAddressController
- Optimize database queries by batching address lookups instead of individual calls

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add getWalletOwnersBatch method for batch wallet owner lookups
- Add shouldSendBatch method for batch notification deduplication
- Optimize shouldSendBatch with HashMap for O(1) lookups instead of O(n²) nested loops
- Update ISubscriptionClient interface with new batch method signatures

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace sequential getWalletOwners calls inside loop with single batch call
- Extract unique account IDs and fetch wallet owners upfront using getWalletOwnersBatch
- Improve performance from O(n) API calls to O(1) batch call for n events
- Maintain same functionality while reducing network overhead and latency

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add getWalletOwnersBatch mock method to SubscriptionClient test mocks
- Add shouldSendBatch mock method to SubscriptionClient test mocks
- Ensure test files compile with new batch method signatures
- Maintain test coverage for refactored batch processing functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@LeonardoVieira1630 LeonardoVieira1630 self-assigned this Aug 28, 2025
@LeonardoVieira1630 LeonardoVieira1630 added the enhancement New feature or request label Aug 28, 2025
@LeonardoVieira1630 LeonardoVieira1630 marked this pull request as ready for review August 28, 2025 13:20
@LeonardoVieira1630 LeonardoVieira1630 linked an issue Aug 28, 2025 that may be closed by this pull request
9 tasks
LeonardoVieira1630 and others added 13 commits August 28, 2025 10:45
- Change triggerHandlers to support arrays of handlers per trigger ID
- Implement parallel execution of handlers using Promise.allSettled
- Add result aggregation combining messageIds and using latest timestamp
- Add fault-tolerant error handling that logs failures but doesn't break service
- Throw error only when all handlers fail
- Add comprehensive tests for multiple handler scenarios

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace multiple parallel getWalletOwners calls with single getWalletOwnersBatch call
- Replace multiple shouldSend calls with single shouldSendBatch call
- Reduce API requests from O(n) to O(1) for n addresses and events
- Improve notification deduplication efficiency using batch operations
- Maintain same notification logic while significantly reducing network overhead

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add getWalletOwnersBatch mock method to SubscriptionClient test mocks
- Add shouldSendBatch mock method to SubscriptionClient test mocks
- Ensure test files compile with new batch method signatures
- Maintain test coverage for refactored batch processing functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
LeonardoVieira1630 and others added 4 commits September 2, 2025 11:38
- Modified Consumer App constructor to accept ENS resolver as parameter
- Updated index.ts to create and inject ENS resolver instance
- Enables easier testing by allowing mock injection

This change prepares the codebase for using mock ENS resolver in tests
to avoid async operations that continue after test teardown.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Created MockEnsResolverService that returns synchronous responses
- Avoids real network calls to ENS during tests
- Prevents async operations from continuing after test teardown

This mock resolves the issue where ENS resolution was causing
"import after Jest teardown" errors in integration tests.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
LeonardoVieira1630 and others added 4 commits September 2, 2025 15:53
- Updated startTestApps to use MockEnsResolverService
- Fixed tsconfig to exclude test files from build
- Ensures all integration tests use mock instead of real ENS

This completes the fix for voting-power test interference issue.
All tests now pass consistently without async ENS operations.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
feat: add multiple handlers support to TriggerProcessorService
@LeonardoVieira1630 LeonardoVieira1630 merged commit 3427d6f into dev Sep 3, 2025
@LeonardoVieira1630 LeonardoVieira1630 deleted the feat/batch-operations branch September 3, 2025 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: notification system to use batch requests

2 participants