perf: DynamicFields reads each post type's fields once per check (review M-12 b)

reason() and note() run per key and type of a body check; they now share one
offered() result per post type, so the default storage callback loads each
pod once instead of per call.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-27 23:12:14 +02:00
co-authored by Claude Opus 5.5
parent 14bc954ecc
commit 6288acf0e6
2 changed files with 38 additions and 2 deletions
@@ -51,6 +51,28 @@ final class DynamicFieldsTest extends TestCase
self::assertNull(self::fields()->note('lit_person', 'telefon'));
}
/** Review M-12 (b): reason() and note() read a type's fields (and its Pods storage) once per instance. */
public function testReasonAndNoteReadEachTypeOnce(): void
{
$schema = Mockery::mock(ContentSchema::class);
$schema->shouldReceive('fields')->with('lit_person')->once()->andReturn([
new FieldDefinition('role', 'Funktion', 'string', 'pods', FieldDefinition::WRITABLE),
]);
$storage = 0;
$fields = new DynamicFields($schema, static function (string $type) use (&$storage): ?string {
++$storage;
return 'meta';
});
foreach (['role', 'telefon', 'role'] as $key) {
$fields->reason('lit_person', $key);
$fields->note('lit_person', $key);
}
self::assertSame(1, $storage);
}
private static function content(string $name, array $settings): string
{
return VariableRef::serialize('content', $name, $settings);