Skip to content

Commit 702abeb

Browse files
committed
optimize cache read hot paths
1 parent e4cb140 commit 702abeb

4 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/Cache/CacheSwitch.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public function invalidating(): bool
5454

5555
public function epoch(): string
5656
{
57+
$known = $this->runtime->knownEpoch();
58+
59+
if ($known !== null) {
60+
return $known;
61+
}
62+
5763
return $this->runtime->epoch(fn(): array => $this->readPair());
5864
}
5965

src/Cache/CanonicalRepository.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,9 @@ public function read(
103103
continue;
104104
}
105105

106-
$row = $this->codec->decodeRowObject($rawRow, $state->epoch);
107-
108-
if (
109-
$row === null
110-
|| !$plan->primaryKey->matchesToken(
111-
$row->{$plan->primaryKey->column} ?? null,
112-
$token,
113-
)
114-
) {
106+
$row = $this->codec->decodeRowObject($rawRow, $state->epoch, $plan->primaryKey, $token);
107+
108+
if ($row === null) {
115109
$corrupt = true;
116110
$missingAt[$index] = $token;
117111

src/Support/QueryIdentity.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ public function hash(
2323
string $namespace,
2424
string $operation,
2525
): string {
26-
$dependencyHashes = array_values(array_unique($dependencyHashes));
27-
sort($dependencyHashes, SORT_STRING);
26+
if (count($dependencyHashes) > 1) {
27+
$dependencyHashes = array_values(array_unique($dependencyHashes));
28+
sort($dependencyHashes, SORT_STRING);
29+
}
2830

2931
$prepared = '';
3032

tests/Unit/PrimaryKeyMetadataTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function test_tokens_must_match_the_canonical_value_representation(): voi
5050
$integer = new PrimaryKeyMetadata('id', PrimaryKeyMetadata::INTEGER);
5151
$string = new PrimaryKeyMetadata('uuid', PrimaryKeyMetadata::STRING);
5252

53+
$this->assertTrue($integer->matchesToken(42, 'i:42'));
5354
$this->assertTrue($integer->matchesToken('42', 'i:42'));
5455
$this->assertFalse($integer->matchesToken('42', 's:42'));
5556
$this->assertFalse($integer->matchesToken('42', 'i:0042'));

0 commit comments

Comments
 (0)