Skip to content

Store metadata based on setono/client's Metadata::hasChanged() - #29

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

loevgaard merged 1 commit into
2.xfrom
metadata-has-changed

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Summary

Closes #24. The persister asks setono/client 1.2's Metadata::hasChanged() whether the metadata is changed metadata. It no longer reads a flag off the bundle's ChangeAwareMetadata subclass (ADR-0002).

 DoctrineOrmBasedMetadataPersister::persist()
   if a lazy ghost was never loaded → skip      # checked first: hasChanged() would load it
-  if ChangeAwareMetadata and not dirty → skip
+  if not $metadata->hasChanged() → skip        # any Metadata, also plain Metadata from a custom provider
   find / persist / flush
 src/Client/
-├── ChangeAwareMetadata.php        # overrode set()/remove() to flip a dirty flag
-└── LazyChangeAwareMetadata.php
+└── LazyMetadata.php               # @internal, final, only LazyGhostTrait
  • Requires setono/client ^1.2
  • New clients, EmptyMetadataProvider and the test app's client contexts create plain Metadata
  • Setting a key to the value and expiry it already has no longer writes the row

Evidence

MetadataTest::it_does_not_store_metadata_that_was_set_to_the_value_it_already_has stores the row with its keys in another order, the way MySQL returns a JSON column, then sets a key to its current value:

  • Before: with the hasChanged() check removed, so the persister writes whenever the metadata was used (as ChangeAwareMetadata did after any set()), the test fails in MetadataTest, CustomMetadataClassTest and InterfaceOnlyMetadataClassTest. The request runs an UPDATE.
    After: passes. The request only runs a SELECT.

On SQLite, Doctrine skips the UPDATE when the decoded JSON is identical, so without the reordered keys this test can't tell the two apart. CLAUDE.md now notes this.

  • PHPUnit (141 tests), PHPStan, ECS, composer validate --strict, composer normalize --dry-run, composer-dependency-analyser: pass
  • Infection: 101 of 101 mutants killed (100% MSI)
  • Lowest deps reproduced locally, as CI runs them: PHP 8.1 with Symfony 6.4.0, and PHP 8.2 with Symfony 7.0.0: pass

Merge Danger

Door: two-way

Blast Radius: metadata classes

2.x is unreleased. Apps that create ChangeAwareMetadata, call isDirty() or reference LazyChangeAwareMetadata switch to Metadata and hasChanged() (UPGRADE-2.0.md). Requiring setono/client 1.2 also brings its null-TTL change: set($key, $value) without a TTL now removes the key's expiry. A new functional test pins that down, and UPGRADE-2.0.md describes it.

setono/client 1.2 tracks changes in Metadata itself, so the bundle no
longer needs its ChangeAwareMetadata subclass, which only noticed dropped
expired keys through the library's private call paths. The persister
stores any Metadata only when hasChanged() is true, so a custom provider
that returns plain Metadata no longer writes on every request, and
setting a key to the value and expiry it already has writes nothing.

LazyChangeAwareMetadata becomes an internal, final LazyMetadata.

Closes #24
@loevgaard
loevgaard merged commit 37354f0 into 2.x Nov 23, 2026
19 checks passed
@loevgaard
loevgaard deleted the metadata-has-changed branch November 23, 2026 11:06
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.

Track metadata changes in setono/client instead of a bundle subclass

1 participant