Skip to content

Experiment; WIP: BUGFIX: bugfix/use-md5paths-instead-classnames-to-flush-correctly #3305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions Neos.Flow/Classes/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,41 +348,42 @@ protected function flushClassCachesByChangedFiles(array $changedFiles): void
$objectClassesCache = $this->getCache('Flow_Object_Classes');
$objectConfigurationCache = $this->getCache('Flow_Object_Configuration');
$modifiedAspectClassNamesWithUnderscores = [];
$modifiedClassNamesWithUnderscores = [];
foreach ($changedFiles as $pathAndFilename => $status) {
if (!file_exists($pathAndFilename)) {
continue;
}
$fileContents = file_get_contents($pathAndFilename);
$className = (new PhpAnalyzer($fileContents))->extractFullyQualifiedClassName();
if ($className === null) {
continue;
}
$classNameWithUnderscores = str_replace('\\', '_', $className);
$modifiedClassNamesWithUnderscores[$classNameWithUnderscores] = true;
// // todo fix. cant flush cache
// if (!file_exists($pathAndFilename)) {
// continue;
// }
// $fileContents = file_get_contents($pathAndFilename);
// $className = (new PhpAnalyzer($fileContents))->extractFullyQualifiedClassName();
// if ($className === null) {
// continue;
// }
// $classNameWithUnderscores = str_replace('\\', '_', $className);
// $modifiedClassNamesWithUnderscores[$classNameWithUnderscores] = true;

// If an aspect was modified, the whole code cache needs to be flushed, so keep track of them:
if (substr($classNameWithUnderscores, -6, 6) === 'Aspect') {
$modifiedAspectClassNamesWithUnderscores[$classNameWithUnderscores] = true;
if (str_ends_with($pathAndFilename, 'Aspect.php')) {
$modifiedAspectClassNamesWithUnderscores[$pathAndFilename] = true;
}
// As long as no modified aspect was found, we are optimistic that only part of the cache needs to be flushed:
if (count($modifiedAspectClassNamesWithUnderscores) === 0) {
$objectClassesCache->remove($classNameWithUnderscores);
$objectClassesCache->remove(md5($pathAndFilename));
}
}
$flushDoctrineProxyCache = false;
$flushPolicyCache = false;
if (count($modifiedClassNamesWithUnderscores) > 0) {
if (count($changedFiles) > 0) {
$reflectionStatusCache = $this->getCache('Flow_Reflection_Status');
foreach (array_keys($modifiedClassNamesWithUnderscores) as $classNameWithUnderscores) {
$reflectionStatusCache->remove($classNameWithUnderscores);
if ($flushDoctrineProxyCache === false && preg_match('/_Domain_Model_(.+)/', $classNameWithUnderscores) === 1) {
$flushDoctrineProxyCache = true;
}
if ($flushPolicyCache === false && preg_match('/_Controller_(.+)Controller/', $classNameWithUnderscores) === 1) {
$flushPolicyCache = true;
}
}
// TODO
// foreach (array_keys($modifiedClassNamesWithUnderscores) as $classNameWithUnderscores) {
// $reflectionStatusCache->remove($classNameWithUnderscores);
// if ($flushDoctrineProxyCache === false && preg_match('/_Domain_Model_(.+)/', $classNameWithUnderscores) === 1) {
// $flushDoctrineProxyCache = true;
// }
// if ($flushPolicyCache === false && preg_match('/_Controller_(.+)Controller/', $classNameWithUnderscores) === 1) {
// $flushPolicyCache = true;
// }
// }
$objectConfigurationCache->remove('allCompiledCodeUpToDate');
}
if (count($modifiedAspectClassNamesWithUnderscores) > 0) {
Expand Down
5 changes: 3 additions & 2 deletions Neos.Flow/Classes/Command/CoreCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ public function compileCommand(bool $force = false)
$this->aopProxyClassBuilder->build();
$this->dependencyInjectionProxyClassBuilder->build();

$classCount = $this->proxyClassCompiler->compile();

$dataTemporaryPath = $this->environment->getPathToTemporaryDirectory();
$previousProxyClasses = @include($dataTemporaryPath . 'AvailableProxyClasses.php') ?: [];
$classCount = $this->proxyClassCompiler->compile($previousProxyClasses);

Files::createDirectoryRecursively($dataTemporaryPath);
file_put_contents($dataTemporaryPath . 'AvailableProxyClasses.php', $this->proxyClassCompiler->getStoredProxyClassMap());

Expand Down
2 changes: 1 addition & 1 deletion Neos.Flow/Classes/Core/ProxyClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function loadClass($className)
}

// Loads any known proxied class:
if ($this->classesCache !== null && ($this->availableProxyClasses === null || isset($this->availableProxyClasses[implode('_', $namespaceParts)])) && $this->classesCache->requireOnce(implode('_', $namespaceParts)) !== false) {
if ($this->classesCache !== null && ($md5 = $this->availableProxyClasses[implode('_', $namespaceParts)] ?? null) && $this->classesCache->requireOnce($md5) !== false) {
return true;
}

Expand Down
7 changes: 4 additions & 3 deletions Neos.Flow/Classes/ObjectManagement/Proxy/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function hasCacheEntryForClass(string $fullClassName): bool
*
* @return int Number of classes which have been compiled
*/
public function compile(): int
public function compile(array $previousProxyClasses): int
{
$compiledClasses = [];
foreach ($this->objectManager->getRegisteredClassNames() as $fullOriginalClassNames) {
Expand All @@ -197,11 +197,12 @@ public function compile(): int
$class = new ReflectionClass($fullOriginalClassName);
$classPathAndFilename = $class->getFileName();
$this->cacheOriginalClassFileAndProxyCode($fullOriginalClassName, $classPathAndFilename, $proxyClassCode);
$this->storedProxyClasses[str_replace('\\', '_', $fullOriginalClassName)] = true;
$this->storedProxyClasses[str_replace('\\', '_', $fullOriginalClassName)] = md5($classPathAndFilename);
$compiledClasses[] = $fullOriginalClassName;
}
} elseif ($this->classesCache->has(str_replace('\\', '_', $fullOriginalClassName))) {
$this->storedProxyClasses[str_replace('\\', '_', $fullOriginalClassName)] = true;
assert($previousProxyClasses[str_replace('\\', '_', $fullOriginalClassName)]);
$this->storedProxyClasses[str_replace('\\', '_', $fullOriginalClassName)] = $previousProxyClasses[str_replace('\\', '_', $fullOriginalClassName)];
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions Neos.Flow/Classes/Reflection/ReflectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ protected function reflectClass(string $className): void
// Development context.
ksort($this->classReflectionData);

$this->updatedReflectionData[$className] = true;
$this->updatedReflectionData[$className] = md5($class->getFileName());
}

/**
Expand Down Expand Up @@ -1757,11 +1757,12 @@ protected function forgetChangedClasses(): void
}
}

foreach ($classNames as $className) {
if (!$this->statusCache->has($this->produceCacheIdentifierFromClassName($className))) {
$this->forgetClass($className);
}
}
// impossible without the path saved in classReflectionData
// foreach ($classNames as $className) {
// if (!$this->statusCache->has($this->produceCacheIdentifierFromClassName($className))) {
// $this->forgetClass($className);
// }
// }
}

/**
Expand Down Expand Up @@ -2080,8 +2081,8 @@ protected function updateReflectionData(): void
{
$this->log(sprintf('Found %s classes whose reflection data was not cached previously.', count($this->updatedReflectionData)), LogLevel::DEBUG);

foreach (array_keys($this->updatedReflectionData) as $className) {
$this->statusCache->set($this->produceCacheIdentifierFromClassName($className), '');
foreach (array_keys($this->updatedReflectionData) as $md5FileName) {
$this->statusCache->set($md5FileName, '');
}

$data = [];
Expand Down
Loading