Skip to content

Commit

Permalink
fixed RecordingQueryReflector (#240)
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Staab <m.staab@complex-it.de>
  • Loading branch information
staabm and clxmstaab authored Feb 4, 2022
1 parent ffaadc3 commit ac7802e
Show file tree
Hide file tree
Showing 5 changed files with 378 additions and 8,702 deletions.
21 changes: 8 additions & 13 deletions src/QueryReflection/ReflectionCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

final class ReflectionCache
{
public const SCHEMA_VERSION = 'v4-runtime-config';
public const SCHEMA_VERSION = 'v5-runtime-config-bugfix';

/**
* @var string
Expand Down Expand Up @@ -78,9 +78,9 @@ private function lazyReadRecords()
return $this->records;
}

$cache = $this->readCache(true);
if (null !== $cache) {
$this->records = $cache['records'];
$cachedRecords = $this->readCachedRecords(true);
if (null !== $cachedRecords) {
$this->records = $cachedRecords;
} else {
$this->records = [];
}
Expand All @@ -90,13 +90,9 @@ private function lazyReadRecords()
}

/**
* @return array{
* records: array<string, array{error?: ?Error, result?: array<QueryReflector::FETCH_TYPE*, ?Type>}>,
* runtimeConfig: array<string, scalar>,
* schemaVersion: string
* }|null
* @return array<string, array{error?: ?Error, result?: array<QueryReflector::FETCH_TYPE*, ?Type>}>|null
*/
private function readCache(bool $useReadLock): ?array
private function readCachedRecords(bool $useReadLock): ?array
{
if (!is_file($this->cacheFile)) {
if (false === file_put_contents($this->cacheFile, '')) {
Expand Down Expand Up @@ -127,8 +123,7 @@ private function readCache(bool $useReadLock): ?array
throw new ShouldNotHappenException();
}

// @phpstan-ignore-next-line
return $cache;
return $cache['records'];
}

public function persist(): void
Expand All @@ -141,7 +136,7 @@ public function persist(): void
flock(self::$lockHandle, LOCK_EX);

// freshly read the cache as it might have changed in the meantime
$cachedRecords = $this->readCache(false);
$cachedRecords = $this->readCachedRecords(false);

// re-apply all changes to the current cache-state
if (null === $cachedRecords) {
Expand Down
Loading

0 comments on commit ac7802e

Please sign in to comment.