-
-
Notifications
You must be signed in to change notification settings - Fork 38
feat: enhance deduplicateItems with cross-batch/execution tracking #144
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
base: main
Are you sure you want to change the base?
Conversation
- Remove trackProcessedKeys option in favor of deduplicateItems - Add automatic processedKeys tracking when deduplicateItems is enabled - Add maxTrackedKeys option (default: 1000) with FIFO eviction - Enhance onDuplicate callback with existingItem parameter - existingItem is undefined for cross-batch duplicates - existingItem is the item for in-batch duplicates - Remove onSkip callback (consolidated into onDuplicate) - Remove skippedCount from state (no longer needed) - Support both cross-batch and in-batch deduplication - Add clearProcessedKeys() method for key management This change simplifies the API by making deduplicateItems the single option for both in-batch and cross-batch deduplication, following the pattern established by RateLimiter's executionTimes tracking.
- Add 51 new test cases covering deduplication scenarios - Test cross-batch duplicate detection and skipping - Test in-batch deduplication with keep-first/keep-last strategies - Test onDuplicate callback with correct parameters - Test maxTrackedKeys with FIFO eviction behavior - Test clearProcessedKeys() method - Test persistence scenarios with processedKeys - Verify processedKeys state management - Test interaction between cross-batch and in-batch deduplication All 109 batcher tests passing.
Apply the same deduplication pattern as Batcher: - Enhance deduplicateItems to enable automatic processedKeys tracking - Add maxTrackedKeys option with FIFO eviction (default: 1000) - Enhance onDuplicate callback with existingItem parameter - Support both cross-execution and in-queue deduplication - Add clearProcessedKeys() method - Add 58 comprehensive test cases The Queuer now follows the same simplified API pattern as Batcher, where deduplicateItems is the single option controlling both in-queue and cross-execution deduplication. All 553 queuer tests passing.
- Add useBatcherDedup React example demonstrating cross-batch deduplication - Show processedKeys tracking in UI - Demonstrate maxTrackedKeys and clearProcessedKeys() usage - Add visual indicators for cross-batch vs in-batch duplicates - Include comprehensive README with usage examples - Add changeset documenting the new deduplication features The example shows how deduplicateItems now automatically handles both in-batch and cross-batch deduplication with a single option, making it easier to prevent duplicate processing across multiple batch executions.
🦋 Changeset detectedLatest commit: 99708fc The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
View your CI Pipeline Execution ↗ for commit 99708fc
☁️ Nx Cloud last updated this comment at |
|
This is a well-formed PR, I'm just concerned that it adds too much bloat for a feature that can be implemented with an external |
|
That’s a fair point — thanks for calling it out! I’m happy to revisit this with a simpler approach or move it out of the core if that better fits the library’s direction. |
🎯 Changes
This PR enhances the
deduplicateItemsoption to support cross-batch/execution duplicate detection, simplifying the API by consolidating all deduplication functionality under a single option.What Changed
Batcher & Queuer Enhancements:
deduplicateItemsnow automatically tracksprocessedKeysacross batches/executionsmaxTrackedKeysoption (default: 1000) with FIFO evictiononDuplicatecallback withexistingItemparameter to distinguish duplicate types:existingItem === undefined: cross-batch/execution duplicate (already processed)existingItem !== undefined: in-batch/queue duplicateclearProcessedKeys()method for manual key managementUsage Example
Design Rationale
This follows the pattern of
RateLimiter'sexecutionTimestracking:Test Coverage
maxTrackedKeysFIFO eviction behaviorclearProcessedKeys()methodonDuplicatecallback invocationsDocumentation & Examples
examples/react/useBatcherDedupdemonstrating:processedKeysstate displaymaxTrackedKeysandclearProcessedKeys()usage✅ Checklist
pnpm run test:pr.🚀 Release Impact
Changeset:
.changeset/add-deduplication-feature.md