mirror of
https://github.com/e107inc/e107.git
synced 2025-08-18 04:12:00 +02:00
Restored JSON core image generator for performance
PDO SQLite was performing unacceptably poorly. Let's just load the entire integrity image into RAM…
This commit is contained in:
@@ -16,8 +16,12 @@ require_once("e_file_inspector_interface.php");
|
||||
*/
|
||||
abstract class e_file_inspector implements e_file_inspector_interface
|
||||
{
|
||||
protected $currentVersion;
|
||||
private $validatedBitmask;
|
||||
|
||||
protected $defaultDirsCache;
|
||||
protected $customDirsCache;
|
||||
|
||||
/**
|
||||
* Check the integrity of the provided path
|
||||
*
|
||||
@@ -105,10 +109,12 @@ abstract class e_file_inspector implements e_file_inspector_interface
|
||||
*/
|
||||
public function getCurrentVersion()
|
||||
{
|
||||
if ($this->currentVersion) return $this->currentVersion;
|
||||
|
||||
$checksums = $this->getChecksums("index.php");
|
||||
$versions = array_keys($checksums);
|
||||
usort($versions, 'version_compare');
|
||||
return array_pop($versions);
|
||||
return $this->currentVersion = array_pop($versions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,6 +144,27 @@ abstract class e_file_inspector implements e_file_inspector_interface
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function pathToDefaultPath($path)
|
||||
{
|
||||
if (!$this->customDirsCache)
|
||||
{
|
||||
$this->defaultDirsCache = e107::getInstance()->defaultDirs();
|
||||
$customDirs = e107::getInstance()->e107_dirs ? e107::getInstance()->e107_dirs : [];
|
||||
$this->customDirsCache = array_diff_assoc($customDirs, $this->defaultDirsCache);
|
||||
}
|
||||
foreach ($this->customDirsCache as $dirType => $customDir)
|
||||
{
|
||||
if (!isset($this->defaultDirsCache[$dirType])) continue;
|
||||
|
||||
$defaultDir = $this->defaultDirsCache[$dirType];
|
||||
if ($customDir === $defaultDir) continue;
|
||||
|
||||
if (substr($path, 0, strlen($customDir)) === $customDir)
|
||||
$path = $defaultDir . substr($path, strlen($customDir));
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
private function getValidatedBitmask()
|
||||
{
|
||||
if ($this->validatedBitmask !== null) return $this->validatedBitmask;
|
||||
|
114
e107_handlers/e_file_inspector_json.php
Normal file
114
e107_handlers/e_file_inspector_json.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* e107 website system
|
||||
*
|
||||
* Copyright (C) 2008-2020 e107 Inc (e107.org)
|
||||
* Released under the terms and conditions of the
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||
*/
|
||||
|
||||
require_once("e_file_inspector.php");
|
||||
|
||||
class e_file_inspector_json extends e_file_inspector
|
||||
{
|
||||
private $coreImage;
|
||||
|
||||
/**
|
||||
* @param $jsonFilePath string Absolute path to the file inspector database
|
||||
*/
|
||||
public function __construct($jsonFilePath = null)
|
||||
{
|
||||
global $core_image;
|
||||
if ($jsonFilePath === null) $jsonFilePath = e_ADMIN . "core_image.php";
|
||||
require($jsonFilePath);
|
||||
$this->coreImage = json_decode($core_image, true);
|
||||
unset($core_image);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getPathIterator($version = null)
|
||||
{
|
||||
$result = self::array_slash($this->coreImage);
|
||||
if (!empty($version))
|
||||
{
|
||||
$result = array_filter($result, function ($value) use ($version)
|
||||
{
|
||||
return array_key_exists($version, $value);
|
||||
});
|
||||
}
|
||||
return new ArrayIterator(array_keys($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getChecksums($path)
|
||||
{
|
||||
$path = $this->pathToDefaultPath($path);
|
||||
return self::array_get($this->coreImage, $path, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from an array using "slash" notation.
|
||||
*
|
||||
* Based on Illuminate\Support\Arr::get()
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
* @copyright Copyright (c) Taylor Otwell
|
||||
* @license https://github.com/illuminate/support/blob/master/LICENSE.md MIT License
|
||||
*/
|
||||
private static function array_get($array, $key, $default = null)
|
||||
{
|
||||
if (is_null($key)) return $array;
|
||||
|
||||
if (isset($array[$key])) return $array[$key];
|
||||
|
||||
foreach (explode('/', $key) as $segment)
|
||||
{
|
||||
if (!is_array($array) || !array_key_exists($segment, $array))
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
|
||||
$array = $array[$segment];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten a multi-dimensional associative array with slashes.
|
||||
* Excludes the second-to-last level of depth from flattening.
|
||||
*
|
||||
* Based on Illuminate\Support\Arr::dot()
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $prepend
|
||||
* @return array
|
||||
* @copyright Copyright (c) Taylor Otwell
|
||||
* @license https://github.com/illuminate/support/blob/master/LICENSE.md MIT License
|
||||
*/
|
||||
private static function array_slash($array, $prepend = '')
|
||||
{
|
||||
$results = array();
|
||||
|
||||
foreach ($array as $key => $value)
|
||||
{
|
||||
if (is_array($value) && is_array(reset($value)))
|
||||
{
|
||||
$results = array_merge($results, self::array_slash($value, $prepend . $key . '/'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$results[$prepend . $key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
@@ -12,10 +12,6 @@ require_once("e_file_inspector.php");
|
||||
class e_file_inspector_sqlphar extends e_file_inspector
|
||||
{
|
||||
private $coreImage;
|
||||
private $currentVersion;
|
||||
|
||||
private $defaultDirsCache;
|
||||
private $customDirsCache;
|
||||
|
||||
/**
|
||||
* e_file_inspector_sqlphar constructor.
|
||||
@@ -87,26 +83,7 @@ class e_file_inspector_sqlphar extends e_file_inspector
|
||||
return $this->currentVersion = $statement->fetchColumn();
|
||||
}
|
||||
|
||||
private function pathToDefaultPath($path)
|
||||
{
|
||||
if (!$this->customDirsCache)
|
||||
{
|
||||
$this->defaultDirsCache = e107::getInstance()->defaultDirs();
|
||||
$customDirs = e107::getInstance()->e107_dirs ? e107::getInstance()->e107_dirs : [];
|
||||
$this->customDirsCache = array_diff_assoc($customDirs, $this->defaultDirsCache);
|
||||
}
|
||||
foreach ($this->customDirsCache as $dirType => $customDir)
|
||||
{
|
||||
if (!isset($this->defaultDirsCache[$dirType])) continue;
|
||||
|
||||
$defaultDir = $this->defaultDirsCache[$dirType];
|
||||
if ($customDir === $defaultDir) continue;
|
||||
|
||||
if (substr($path, 0, strlen($customDir)) === $customDir)
|
||||
$path = $defaultDir . substr($path, strlen($customDir));
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy file to destination with low memory footprint
|
||||
|
Reference in New Issue
Block a user