Skip to content

feat(repository): add bulkDelete() and bulkUpdate() for mass operations#147

Merged
clementtalleu merged 1 commit into
clementtalleu:mainfrom
guillaumedelre:feature/issue-146
May 11, 2026
Merged

feat(repository): add bulkDelete() and bulkUpdate() for mass operations#147
clementtalleu merged 1 commit into
clementtalleu:mainfrom
guillaumedelre:feature/issue-146

Conversation

@guillaumedelre
Copy link
Copy Markdown
Contributor

Ref: #146

Implement BulkOperations without loading objects into memory:

  • ClassMetadata: expose uniqueConstraints, hasUniqueConstraints(), getUniqueFields()
  • MetadataFactory: read #[Unique] property-level and class-level into ClassMetadata
  • RedisObjectManager: cache ClassMetadata per class; refactor buildUniqueConstraintPlan() to read pre-computed metadata instead of repeating reflection on every flush()
  • AbstractObjectRepository: lazy ClassMetadata cache via getClassMetadata()
  • RedisClientInterface + RedisClient + PredisClient: three new methods:
    • searchKeys() FT.SEARCH ... NOCONTENT (keys only, no deserialization)
    • searchKeysWithFields() FT.SEARCH ... RETURN n fields (keys + selected field values)
    • delMultiple() DEL key1 key2 ... (single command)
  • bulkDelete(criteria): FT.SEARCH per batch + delMultiple; unique constraint keys
    (unique:{class}:{fields}:{values}) cleaned up automatically
  • bulkUpdate(criteria, changes): FT.SEARCH per batch + hMSet/jsonSetProperty per key;
    throws BulkOperationException when changes target a unique-constraint field
  • BulkOperationException: new exception for invalid bulk update on unique fields
  • Functional tests: 18 tests covering Hash and JSON for all scenarios
  • docs/advanced_usage.md: bulk operations section with decision table
  • README.md: Bulk Operations section + feature list entry

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 7, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 74.07407% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.85%. Comparing base (3c6b698) to head (638fcd0).

Files with missing lines Patch % Lines
src/Client/RedisClient.php 0.00% 47 Missing ⚠️
src/Client/PredisClient.php 85.41% 7 Missing ⚠️
src/Om/Repository/AbstractObjectRepository.php 97.72% 2 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #147      +/-   ##
============================================
- Coverage     87.47%   86.85%   -0.63%     
- Complexity      951     1017      +66     
============================================
  Files            70       71       +1     
  Lines          2228     2404     +176     
============================================
+ Hits           1949     2088     +139     
- Misses          279      316      +37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Implement BulkOperations without loading objects into memory:

- ClassMetadata: expose uniqueConstraints, hasUniqueConstraints(), getUniqueFields()
- MetadataFactory: read #[Unique] property-level and class-level into ClassMetadata
- RedisObjectManager: cache ClassMetadata per class; refactor buildUniqueConstraintPlan()
  to read pre-computed metadata instead of repeating reflection on every flush()
- AbstractObjectRepository: lazy ClassMetadata cache via getClassMetadata()
- RedisClientInterface + RedisClient + PredisClient: three new methods:
    searchKeys()             FT.SEARCH ... NOCONTENT (keys only, no deserialization)
    searchKeysWithFields()   FT.SEARCH ... RETURN n fields (keys + selected field values)
    delMultiple()            DEL key1 key2 ... (single command)
- bulkDelete(criteria): FT.SEARCH per batch + delMultiple; unique constraint keys
  (unique:{class}:{fields}:{values}) cleaned up automatically
- bulkUpdate(criteria, changes): FT.SEARCH per batch + hMSet/jsonSetProperty per key;
  throws BulkOperationException when changes target a unique-constraint field
- BulkOperationException: new exception for invalid bulk update on unique fields
- Functional tests: 18 tests covering Hash and JSON for all scenarios
- docs/advanced_usage.md: bulk operations section with decision table
- README.md: Bulk Operations section + feature list entry
@guillaumedelre
Copy link
Copy Markdown
Contributor Author

@clementtalleu I forgot to mention that for the case of a mass delete, this avoided having to do a foreach loop and call $objectManager->remove($entity); for example

// Before: looping and removing one by one
foreach ($entities as $entity) {
    $objectManager->remove($entity);
}
$objectManager->flush();

// After: single bulk delete query
$count = $repository->bulkDelete(['status' => 'inactive']);

@clementtalleu clementtalleu merged commit 833659e into clementtalleu:main May 11, 2026
3 checks passed
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.

3 participants