feat: tier 4 — eliminate N+1 query loops on hot paths#119
Merged
Conversation
Rebased onto merged Tier 1-3: F4 (cache-redis batched MGET/pipeline) must preserve Tier 1's HMAC value signing (verify-unwrap on read, wrap on write); every hand-written ConnectionInterface stub needs Tier 2's driverName(); exists-family must stop delegating; F3/F5 @throws + error-wrapping clarified. Dependency graph (002<-001, 005<-004) verified. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Audit remediation Tier 4 — all 7 tasks, TDD, full-suite green (6537 passing). Built on merged Tier 1-3. - F1 Repository::findOneBy now issues a single LIMIT 1 query (still eager-loaded, no full hydration of all matches); exists/existsBy/isColumnUnique use a SELECT 1 ... LIMIT 1 boolean probe (no hydration, no eager-load). - F2 AttachmentManager::findByAttachable resolves all attachments via one MediaRepositoryInterface::findMany(array) call instead of per-id find() (interface-only; consumer owns the WHERE IN query). - F3 AdminUserProvider resolves all role permissions in ONE query via RoleRepositoryInterface::getPermissionsForRoles(array) (empty list → no query, never IN ()); syncPermissions is now transactional + chunked batched insert. - F4 RedisCacheDriver multi-key ops use one MGET / one pipeline / one variadic DEL — preserving Tier 1's HMAC value signing (verify-unwrap on read, wrap on write). - F5 new opt-in BatchChannelInterface; DatabaseChannel persists N recipients via one chunked multi-row INSERT; NotificationSender groups per-channel and falls back to per-recipient send for non-batch channels. ChannelInterface unchanged. Devil's-advocate-reviewed (HMAC-signer preservation + driverName() stubs), standards-enforced (no src readonly-class promotions), docs updated, phpcs + php-cs-fixer clean. Includes a test-fixture fix (renamed a colliding global makeNotifiable() helper that clashed with notification-database's). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Tier 4 — Performance / N+1 Fixes
Fourth of six audit-remediation PRs. Eliminates N+1 query loops and missing
LIMIT 1on hot lookup/attachment/admin-auth/Redis/notification paths. 7 TDD tasks, full suite green (6537 passing, 0 failures). Built on Tier 1-3.findOneByfetched+hydrated ALL matches;existsfamily hydrated entitiesfindOneBy→ singleLIMIT 1(still eager-loaded);exists/existsBy/isColumnUnique→SELECT 1 … LIMIT 1boolean probe (no hydration).AttachmentManagerloopedfind()per attachment idMediaRepositoryInterface::findMany(array)call, reorder + null-skip in PHP.getPermissionsForRoles(array)query for all roles (empty → no query, neverIN ());syncPermissionsnow transactional + chunked batch insert.BatchChannelInterface;DatabaseChannelpersists N recipients via one chunked multi-row INSERT; sender falls back to per-recipientsendfor non-batch channels.Public surface
MediaRepositoryInterface::findMany(array): array(new; consumers implementing the interface must add it).RoleRepositoryInterface::getPermissionsForRoles(array): array(new).BatchChannelInterface(new, opt-in —ChannelInterfaceunchanged).Process
Devil's-advocate-reviewed (caught the F4 HMAC-signer-preservation requirement and the
driverName()stub ripple from Tier 2), standards-enforced (nosrc/readonly classpromotions per the Tier 3 lesson), docs updated, phpcs + php-cs-fixer clean.🤖 Generated with Claude Code