Skip to content

Fold the metadata provider and persister into one metadata store - #30

Merged
loevgaard merged 1 commit into
2.xfrom
metadata-store
Nov 23, 2026
Merged

loevgaard merged 1 commit into
2.xfrom
metadata-store

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Summary

One seam, MetadataStoreInterface, replaces the metadata provider and the metadata persister. The "no query, no write unless the metadata is used" guarantee now lives in one class instead of a protocol split across two.

 CookieBasedClientContext::getClient()
-  metadataProvider->getMetadata(clientId)    # Doctrine provider → EmptyMetadataProvider fallback
+  metadataStore->load(clientId)              # lazy ghost; empty metadata when the client has no row

 StoreMetadataSubscriber (kernel.finish_request, main request)
-  metadataPersister->persist(currentClient)  # looked up the entity manager before its skip checks
+  metadataStore->store(currentClient)
DoctrineOrmBasedMetadataStore::store(client)
  if metadata is a lazy ghost that was never loaded → return
  if !metadata.hasChanged()                         → return
  look up the entity manager                        # only now
  find or create the row, set the metadata, flush   # unchanged, incl. swallowing a unique-constraint violation
-setono_client.metadata_provider.{default,empty,doctrine_orm_based}
-setono_client.metadata_persister.{default,doctrine_orm_based}
+MetadataStoreInterface → setono_client.metadata_store.default → setono_client.metadata_store.doctrine_orm_based
  • The interface's docblock makes both rules the contract: load() doesn't touch storage until the metadata is used, and store() stores only changed metadata.
  • CookieBasedClientContext and StoreMetadataSubscriber inject the interface, so an app's decorator of the store handles both loading and storing.
  • A client without a stored row gets empty metadata. The fallback to a decorated provider is gone with no replacement.
  • The Prophecy tests that doubled the entity manager are replaced by functional tests on SQLite.
  • UPGRADE-2.0.md gets a "Metadata store" section with a porting guide. The README and CLAUDE.md describe the store.

Closes #23

Evidence

  • Before: the new it_does_not_start_the_entity_manager_when_the_metadata_is_not_used and it_does_not_start_the_entity_manager_for_a_new_visitor_that_does_not_use_metadata failed in all three kernel environments: 6 failures, Failed asserting that true is false. The old persister looked up the entity manager on every request.
    After: both pass. The full suite passes with 151 tests. PHPStan and ECS are clean.
  • Before: a decorator of MetadataStoreInterface that one of the classes skipped. To simulate this, I pointed either CookieBasedClientContext or StoreMetadataSubscriber at setono_client.metadata_store.default. DecoratedMetadataStoreTest then fails: Failed asserting that two arrays are identical.
    After: with the interface injected, the request loads and stores through the decorator.
  • New functional tests replace the cases only the deleted unit tests covered:
    • no query for a new visitor, or for a returning visitor without a stored row
    • empty metadata for a returning visitor without a row, and storing it
    • no write when the metadata was only read
  • Infection: 102 of 102 mutants killed. MSI and covered MSI are both 100%, with no ignored mutants.

Merge Danger

Door: two-way

2.x is unreleased, so a revert restores the provider and the persister.

Blast Radius: extension API

An app that implemented or decorated MetadataProviderInterface or MetadataPersisterInterface has to port to MetadataStoreInterface. So does an app that relied on the provider fallback for a client without a stored row. Apps that only use $client->metadata see no change.

The guarantee that a request which doesn't use metadata neither queries
nor writes was a protocol split across two seams: the provider chose a
lazy ghost, and the persister recovered that choice with instanceof.
MetadataStoreInterface now owns both halves. Its docblock makes them the
contract: load() doesn't touch storage until the metadata is used, and
store() stores only changed metadata. DoctrineOrmBasedMetadataStore keeps
both rules and looks up the entity manager only when it writes.

A client without a stored row gets empty metadata. The fallback to a
decorated provider is gone with no replacement. CookieBasedClientContext
and StoreMetadataSubscriber inject the interface, so a decorator of the
store handles both loading and storing.

The provider and persister interfaces, their three classes and their
service ids are removed. Their Prophecy tests, which doubled the entity
manager, are replaced by functional tests on SQLite.

Closes #23
@loevgaard
loevgaard merged commit ea8cb5d into 2.x Nov 23, 2026
19 checks passed
@loevgaard
loevgaard deleted the metadata-store branch November 23, 2026 14:03
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.

Fold the metadata provider and persister into one metadata store

1 participant