Merge pull request #7997 from kkmuffme/change-cache-hash-type-for-better-performance

change cache hash type for better performance
pull/8007/head
orklah 2 years ago committed by GitHub
commit ee6c10563a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,15 +13,17 @@ use function file_get_contents;
use function file_put_contents;
use function filemtime;
use function get_class;
use function hash;
use function igbinary_serialize;
use function igbinary_unserialize;
use function is_dir;
use function mkdir;
use function phpversion;
use function serialize;
use function sha1;
use function strtolower;
use function unlink;
use function unserialize;
use function version_compare;
use const DIRECTORY_SEPARATOR;
@ -111,7 +113,8 @@ class ClassLikeStorageCacheProvider
private function getCacheHash(?string $file_path, ?string $file_contents): string
{
return sha1(($file_path ? $file_contents : '') . $this->modified_timestamps);
$data = ($file_path ? $file_contents : '') . $this->modified_timestamps;
return version_compare(phpversion(), '8.1', '>=') ? hash('xxh128', $data) : hash('md4', $data);
}
/**
@ -161,9 +164,13 @@ class ClassLikeStorageCacheProvider
mkdir($parser_cache_directory, 0777, true);
}
$data = $file_path ? strtolower($file_path) . ' ' : '';
$data .= $fq_classlike_name_lc;
$file_path_sha = version_compare(phpversion(), '8.1', '>=') ? hash('xxh128', $data) : hash('md4', $data);
return $parser_cache_directory
. DIRECTORY_SEPARATOR
. sha1(($file_path ? strtolower($file_path) . ' ' : '') . $fq_classlike_name_lc)
. $file_path_sha
. ($this->config->use_igbinary ? '-igbinary' : '');
}
}

@ -13,15 +13,17 @@ use function file_get_contents;
use function file_put_contents;
use function filemtime;
use function get_class;
use function hash;
use function igbinary_serialize;
use function igbinary_unserialize;
use function is_dir;
use function mkdir;
use function phpversion;
use function serialize;
use function sha1;
use function strtolower;
use function unlink;
use function unserialize;
use function version_compare;
use const DIRECTORY_SEPARATOR;
@ -118,7 +120,8 @@ class FileStorageCacheProvider
private function getCacheHash(string $file_path, string $file_contents): string
{
return sha1(strtolower($file_path) . ' ' . $file_contents . $this->modified_timestamps);
$data = ($file_path ? $file_contents : '') . $this->modified_timestamps;
return version_compare(phpversion(), '8.1', '>=') ? hash('xxh128', $data) : hash('md4', $data);
}
/**
@ -165,9 +168,15 @@ class FileStorageCacheProvider
mkdir($parser_cache_directory, 0777, true);
}
if (version_compare(phpversion(), '8.1', '>=')) {
$hash = hash('xxh128', $file_path);
} else {
$hash = hash('md4', $file_path);
}
return $parser_cache_directory
. DIRECTORY_SEPARATOR
. sha1($file_path)
. $hash
. ($this->config->use_igbinary ? '-igbinary' : '');
}
}

@ -8,9 +8,11 @@ use function file_exists;
use function file_get_contents;
use function file_put_contents;
use function filemtime;
use function hash;
use function mkdir;
use function sha1;
use function phpversion;
use function touch;
use function version_compare;
use const DIRECTORY_SEPARATOR;
@ -91,11 +93,15 @@ class ProjectCacheProvider
return true;
}
$sha1 = sha1($lockfile_contents);
if (version_compare(phpversion(), '8.1', '>=')) {
$hash = hash('xxh128', $lockfile_contents);
} else {
$hash = hash('md4', $lockfile_contents);
}
$changed = $sha1 !== $this->getComposerLockHash();
$changed = $hash !== $this->getComposerLockHash();
$this->composer_lock_hash = $sha1;
$this->composer_lock_hash = $hash;
return $changed;
}

Loading…
Cancel
Save