Skip to content

Add PK identity map to AbstractMapper, consolidate $pending#21

Merged
alganet merged 1 commit intoRespect:masterfrom
alganet:pk-track
Mar 25, 2026
Merged

Add PK identity map to AbstractMapper, consolidate $pending#21
alganet merged 1 commit intoRespect:masterfrom
alganet:pk-track

Conversation

@alganet
Copy link
Copy Markdown
Member

@alganet alganet commented Mar 25, 2026

Replace three SplObjectStorage mutation registries ($new, $changed, $removed) with a single $pending mapping entity/operation ('insert'|'update'|'delete').

Add identity map infrastructure to AbstractMapper so any backend can leverage PK-indexed entity caching:

  • registerInIdentityMap() / evictFromIdentityMap() for write operations
  • findInIdentityMap() for read shortcut on scalar PK lookups
  • clearIdentityMap() / identityMapCount() / trackedCount() for observability

InMemoryMapper updated to use $pending and identity map throughout. Tests added covering fetch caching, insert/delete eviction, reset behavior, and pending operation types.

@alganet alganet requested a review from Copilot March 25, 2026 10:52
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 93.02326% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.58%. Comparing base (731ed33) to head (132900c).

Files with missing lines Patch % Lines
src/AbstractMapper.php 93.02% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #21      +/-   ##
============================================
- Coverage     98.12%   97.58%   -0.54%     
- Complexity      186      206      +20     
============================================
  Files            16       16              
  Lines           427      456      +29     
============================================
+ Hits            419      445      +26     
- Misses            8       11       +3     

☔ 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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR consolidates unit-of-work mutation tracking into a single $pending operation map and introduces a PK-indexed identity map in AbstractMapper to enable cached entity reuse on scalar primary-key fetches across backends.

Changes:

  • Replace $new/$changed/$removed registries with a single $pending: entity → ('insert'|'update'|'delete').
  • Add identity map infrastructure to AbstractMapper (register/evict/find/clear + count helpers).
  • Update InMemoryMapper to use $pending and identity map; add tests for caching and pending operation types.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/AbstractMapper.php Introduces $pending and identity map APIs; updates persist/remove/reset behavior accordingly.
tests/InMemoryMapper.php Implements pending-based flush and identity-map-backed fetch behavior in the in-memory test mapper.
tests/AbstractMapperTest.php Updates reset test for pending; adds identity map and pending operation-type tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Replace three SplObjectStorage mutation registries ($new, $changed, $removed)
with a single $pending mapping entity/operation ('insert'|'update'|'delete').

Add identity map infrastructure to AbstractMapper so any backend can leverage
PK-indexed entity caching:
- registerInIdentityMap() / evictFromIdentityMap() for write operations
- findInIdentityMap() for read shortcut on scalar PK lookups
- clearIdentityMap() / identityMapCount() / trackedCount() for observability

InMemoryMapper updated to use $pending and identity map throughout.
Tests added covering fetch caching, insert/delete eviction, reset behavior,
and pending operation types.
@alganet alganet marked this pull request as ready for review March 25, 2026 11:26
@alganet alganet merged commit 169cf0b into Respect:master Mar 25, 2026
3 checks passed
@alganet alganet deleted the pk-track branch March 25, 2026 11:26
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