Skip to content

Commit

Permalink
fix benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Dec 15, 2023
1 parent a440d0b commit df4d467
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/Aggregate/AggregateRootAttributeBehaviour.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait AggregateRootAttributeBehaviour
use AggregateRootMetadataAwareBehaviour;

#[Ignore]
private AggregateRootId|null $_aggregateRootId = null;
private AggregateRootId|null $cachedAggregateRootId = null;

protected function apply(object $event): void

Check warning on line 20 in src/Aggregate/AggregateRootAttributeBehaviour.php

View workflow job for this annotation

GitHub Actions / Mutation tests (locked, 8.3, ubuntu-latest)

Escaped Mutant for Mutator "ProtectedVisibility": --- Original +++ New @@ @@ use AggregateRootMetadataAwareBehaviour; #[Ignore] private AggregateRootId|null $cachedAggregateRootId = null; - protected function apply(object $event) : void + private function apply(object $event) : void { $metadata = static::metadata(); if (!array_key_exists($event::class, $metadata->applyMethods)) {
{
Expand All @@ -35,8 +35,8 @@ protected function apply(object $event): void

public function aggregateRootId(): AggregateRootId
{
if ($this->_aggregateRootId instanceof AggregateRootId) {
return $this->_aggregateRootId;
if ($this->cachedAggregateRootId instanceof AggregateRootId) {

Check warning on line 38 in src/Aggregate/AggregateRootAttributeBehaviour.php

View workflow job for this annotation

GitHub Actions / Mutation tests (locked, 8.3, ubuntu-latest)

Escaped Mutant for Mutator "InstanceOf_": --- Original +++ New @@ @@ } public function aggregateRootId() : AggregateRootId { - if ($this->cachedAggregateRootId instanceof AggregateRootId) { + if (false) { return $this->cachedAggregateRootId; } $metadata = static::metadata();
return $this->cachedAggregateRootId;
}

$metadata = static::metadata();
Expand All @@ -50,6 +50,6 @@ public function aggregateRootId(): AggregateRootId
throw new AggregateIdNotSupported($this::class, $aggregateId);
}

return $this->_aggregateRootId = $aggregateId;
return $this->cachedAggregateRootId = $aggregateId;
}
}
7 changes: 2 additions & 5 deletions tests/Benchmark/BasicImplementation/Aggregate/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Patchlevel\EventSourcing\Aggregate\BasicAggregateRoot;
use Patchlevel\EventSourcing\Attribute\Aggregate;
use Patchlevel\EventSourcing\Attribute\AggregateId;
use Patchlevel\EventSourcing\Attribute\Apply;
use Patchlevel\EventSourcing\Attribute\Snapshot;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Events\NameChanged;
Expand All @@ -18,15 +19,11 @@
#[Snapshot('default')]
final class Profile extends BasicAggregateRoot
{
#[AggregateId]
#[ProfileIdNormalizer]
private ProfileId $id;
private string $name;

public function aggregateRootId(): string
{
return $this->id->toString();
}

public static function create(ProfileId $id, string $name): self
{
$self = new self();
Expand Down
4 changes: 3 additions & 1 deletion tests/Benchmark/BasicImplementation/ProfileId.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation;

use Patchlevel\EventSourcing\Aggregate\AggregateRootId;

use function uniqid;

final class ProfileId
final class ProfileId implements AggregateRootId
{
private function __construct(
private string $id,
Expand Down
2 changes: 1 addition & 1 deletion tests/Benchmark/SimpleSetupBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function setUp(): void
#[Bench\Revs(20)]
public function benchLoad10000Events(): void
{
$this->repository->load('1');
$this->repository->load(ProfileId::fromString('1'));
}

#[Bench\Revs(20)]
Expand Down
4 changes: 2 additions & 2 deletions tests/Benchmark/SnapshotsBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public function setUp(): void
public function benchLoad10000EventsMissingSnapshot(): void
{
$this->adapter->clear();
$this->repository->load('1');
$this->repository->load(ProfileId::fromString('1'));
}

#[Bench\Revs(20)]
public function benchLoad10000Events(): void
{
$this->repository->load('1');
$this->repository->load(ProfileId::fromString('1'));
}
}
2 changes: 1 addition & 1 deletion tests/Benchmark/SplitStreamBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function provideData(): void
#[Bench\BeforeMethods('provideData')]
public function benchLoad10000Events(): void
{
$this->repository->load('1');
$this->repository->load(ProfileId::fromString('1'));
}

#[Bench\Revs(20)]
Expand Down

0 comments on commit df4d467

Please sign in to comment.