Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/240318

Change subject: Use FileContentsHasher in ResourceLoaderModule::safeFileHash
......................................................................

Use FileContentsHasher in ResourceLoaderModule::safeFileHash

Replace the one-off code for APC-assisted file content hashing from I5ceb8537c
with a call to the FileContentsHasher class introduced in I1ff61153.

Change-Id: I8e4c3d5a5e7cdf6455a43769261d742b0255622c
---
M includes/resourceloader/ResourceLoaderModule.php
1 file changed, 4 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/18/240318/1

diff --git a/includes/resourceloader/ResourceLoaderModule.php 
b/includes/resourceloader/ResourceLoaderModule.php
index 1d3ffb5..efb98e7 100644
--- a/includes/resourceloader/ResourceLoaderModule.php
+++ b/includes/resourceloader/ResourceLoaderModule.php
@@ -857,34 +857,15 @@
         * @return string Hash
         */
        protected static function safeFileHash( $filePath ) {
-               static $cache;
+               static $hasher;
 
-               if ( !$cache ) {
-                       $cache = ObjectCache::newAccelerator( CACHE_NONE );
+               if ( !$hasher ) {
+                       $hasher = new FileContentsHasher;
                }
 
                MediaWiki\suppressWarnings();
-               $mtime = filemtime( $filePath );
+               $hash = $hasher->getFileContentHash( $filePath );
                MediaWiki\restoreWarnings();
-               if ( !$mtime ) {
-                       return '';
-               }
-
-               $cacheKey = wfGlobalCacheKey( 'resourceloader', __METHOD__, 
$filePath );
-               $cachedHash = $cache->get( $cacheKey );
-               if ( isset( $cachedHash['mtime'] ) && $cachedHash['mtime'] === 
$mtime ) {
-                       return $cachedHash['hash'];
-               }
-
-               MediaWiki\suppressWarnings();
-               $contents = file_get_contents( $filePath );
-               MediaWiki\restoreWarnings();
-               if ( !$contents ) {
-                       return '';
-               }
-
-               $hash = hash( 'md4', $contents );
-               $cache->set( $cacheKey, array( 'mtime' => $mtime, 'hash' => 
$hash ), 60 * 60 * 24 );
 
                return $hash;
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/240318
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8e4c3d5a5e7cdf6455a43769261d742b0255622c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <o...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to