Skip to content

Commit

Permalink
use is_file() instead of file_exists() which is up to 100x faster (#3556
Browse files Browse the repository at this point in the history
)

* use is_file() instead of file_exists() which is up to 100x faster

* Update redaxo/src/addons/backup/vendor/tar.php

Co-Authored-By: Gregor Harlan <mail@gh01.de>

* Update redaxo/src/addons/media_manager/lib/effects/effect_insert_image.php

* Update redaxo/src/addons/phpmailer/install.php

* Update redaxo/src/addons/backup/lib/tar.php

Co-Authored-By: Gregor Harlan <mail@gh01.de>

* Update redaxo/src/addons/install/lib/package/package_download.php

Co-Authored-By: Gregor Harlan <mail@gh01.de>

Co-authored-by: Gregor Harlan <mail@gh01.de>
  • Loading branch information
staabm and gharlan committed Apr 26, 2020
1 parent a4cfc38 commit 3ee969f
Show file tree
Hide file tree
Showing 36 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion redaxo/src/addons/backup/lib/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public static function getTables()

private static function importScript($filename, $importType, $eventType)
{
if (file_exists($filename)) {
if (is_file($filename)) {
require $filename;
}
}
Expand Down
4 changes: 2 additions & 2 deletions redaxo/src/addons/backup/lib/cronjob.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public function execute()
$blacklist_tables = explode('|', $this->getParam('blacklist_tables'));
$whitelist_tables = array_diff($tables, $blacklist_tables);

if (file_exists($dir . $file . $ext)) {
if (is_file($dir . $file . $ext)) {
$i = 1;
while (file_exists($dir . $file . '_' . $i . $ext)) {
while (is_file($dir . $file . '_' . $i . $ext)) {
++$i;
}
$file = $file . '_' . $i;
Expand Down
8 changes: 4 additions & 4 deletions redaxo/src/addons/backup/lib/tar.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function openTAR($filename)
unset($this->directories);

// If the tar file doesn't exist...
if (!file_exists($filename)) {
if (!is_file($filename)) {
return false;
}

Expand All @@ -66,7 +66,7 @@ public function openTAR($filename)
public function addFile($filename)
{
// Make sure the file we are adding exists!
if (!file_exists($filename)) {
if (!is_file($filename)) {
return false;
}

Expand Down Expand Up @@ -112,7 +112,7 @@ public function addFile($filename)
*/
public function addDirectory($dirname)
{
if (!file_exists($dirname)) {
if (!is_dir($dirname)) {
return false;
}

Expand Down Expand Up @@ -317,7 +317,7 @@ public function extractTar()
foreach ($this->files as $item) {
// jan: wenn probleme mit der ordnergenerierung -> ordner manuell einstellen

if (!file_exists(dirname($item['name']))) {
if (!is_file(dirname($item['name']))) {
rex_dir::create(dirname($item['name']));
}
if ($h = @fopen($item['name'], 'w+')) {
Expand Down
4 changes: 2 additions & 2 deletions redaxo/src/addons/backup/pages/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
$ext = 'sql' == $exporttype ? '.sql' : '.tar.gz';
$export_path = rex_backup::getDir() . '/';

if (file_exists($export_path . $filename . $ext)) {
if (is_file($export_path . $filename . $ext)) {
$i = 1;
while (file_exists($export_path . $filename . '_' . $i . $ext)) {
while (is_file($export_path . $filename . '_' . $i . $ext)) {
++$i;
}
$filename = $filename . '_' . $i;
Expand Down
8 changes: 4 additions & 4 deletions redaxo/src/addons/backup/vendor/tar.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public function openTAR($filename) {
unset($this->numDirectories);

// If the tar file doesn't exist...
if(!file_exists($filename))
if(!is_file($filename))
return false;

$this->filename = $filename;
Expand All @@ -368,7 +368,7 @@ public function openTAR($filename) {
*/
public function appendTar($filename) {
// If the tar file doesn't exist...
if(!file_exists($filename))
if(!is_file($filename))
return false;

$this->__readTar($filename);
Expand Down Expand Up @@ -442,7 +442,7 @@ public function containsDirectory($dirname) {
* @return bool
*/
public function addDirectory($dirname) {
if(!file_exists($dirname))
if(!is_dir($dirname))
return false;

// Get directory information
Expand Down Expand Up @@ -470,7 +470,7 @@ public function addDirectory($dirname) {
*/
public function addFile($filename) {
// Make sure the file we are adding exists!
if(!file_exists($filename))
if(!is_file($filename))
return false;

// Make sure there are no other files in the archive that have this same filename
Expand Down
4 changes: 2 additions & 2 deletions redaxo/src/addons/be_style/lib/scss_compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public function compile()
$path_parts = pathinfo($path);
$underscore_file = $path_parts['dirname'] . '/_' . $path_parts['basename'];

if (file_exists($underscore_file)) {
if (is_file($underscore_file)) {
$path = $underscore_file;
}

if (!file_exists($path)) {
if (!is_file($path)) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/addons/be_style/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
foreach ($addon->getInstalledPlugins() as $plugin) {
$file = __DIR__.'/plugins/'.$plugin->getName().'/install.php';

if (file_exists($file)) {
if (is_file($file)) {
$plugin->includeFile($file);
}
}
6 changes: 3 additions & 3 deletions redaxo/src/addons/install/lib/api/api_core_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function execute()
foreach (rex_finder::factory($temppath . 'addons')->dirsOnly() as $dir) {
$addonkey = $dir->getBasename();
$addonPath = $dir->getRealPath() . '/';
if (!file_exists($addonPath . rex_package::FILE_PACKAGE)) {
if (!is_file($addonPath . rex_package::FILE_PACKAGE)) {
continue;
}

Expand All @@ -83,11 +83,11 @@ public function execute()
// }
//}
$this->checkRequirements($temppath, $version['version'], $updateAddonsConfig);
if (file_exists($temppath . 'core/update.php')) {
if (is_file($temppath . 'core/update.php')) {
include $temppath . 'core/update.php';
}
foreach ($updateAddons as $addonkey => $addon) {
if ($addon->isInstalled() && file_exists($file = $temppath . 'addons/' . $addonkey . '/' . rex_package::FILE_UPDATE)) {
if ($addon->isInstalled() && is_file($file = $temppath . 'addons/' . $addonkey . '/' . rex_package::FILE_UPDATE)) {
try {
$addon->includeFile($file);
if ($msg = $addon->getProperty('updatemsg', '')) {
Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/addons/install/lib/package/package_download.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ private function isCorrectFormat($file)
return $success;
}

return file_exists("phar://$file/" . $this->addonkey);
return is_dir("phar://$file/" . $this->addonkey);
}
}
4 changes: 2 additions & 2 deletions redaxo/src/addons/install/lib/package/package_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function doAction()

// ---- check package.yml
$packageFile = $temppath . rex_package::FILE_PACKAGE;
if (!file_exists($packageFile)) {
if (!is_file($packageFile)) {
return rex_i18n::msg('package_missing_yml_file');
}
try {
Expand All @@ -58,7 +58,7 @@ public function doAction()
}

// ---- include update.php
if ($this->addon->isInstalled() && file_exists($temppath . rex_package::FILE_UPDATE)) {
if ($this->addon->isInstalled() && is_file($temppath . rex_package::FILE_UPDATE)) {
try {
$this->addon->includeFile('../.new.' . $this->addonkey . '/' . rex_package::FILE_UPDATE);
} catch (rex_functional_exception $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function execute()

// -------------------------------------- CONFIG
$brandimage = rex_path::media($this->params['brandimage']);
if (!file_exists($brandimage) || !is_file($brandimage)) {
if (!is_file($brandimage)) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions redaxo/src/addons/media_manager/lib/managed_media.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function asImage()
return;
}

if (!$this->sourcePath || !file_exists($this->sourcePath)) {
if (!$this->sourcePath || !is_file($this->sourcePath)) {
throw new rex_media_manager_not_found_exception(sprintf('Source path "%s" does not exist.', $this->sourcePath));
}

Expand Down Expand Up @@ -219,7 +219,7 @@ public function save($sourceCacheFilename, $headerCacheFilename)

public function exists(): bool
{
return $this->asImage || file_exists($this->sourcePath);
return $this->asImage || is_file($this->sourcePath);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions redaxo/src/addons/media_manager/lib/media_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function isCached()
{
$cache_file = $this->getCacheFilename();

if (!file_exists($cache_file)) {
if (!is_file($cache_file)) {
return false;
}

Expand All @@ -185,7 +185,7 @@ public function isCached()
return true;
}

if (!file_exists($mediapath)) {
if (!is_file($mediapath)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function rex_mediapool_filename($FILENAME, $doSubindexing = true)
if ($doSubindexing || $FILENAME != $NFILENAME) {
// ----- datei schon vorhanden -> namen aendern -> _1 ..
$cnt = 0;
while (file_exists(rex_path::media($NFILENAME)) || rex_media::get($NFILENAME)) {
while (is_file(rex_path::media($NFILENAME)) || rex_media::get($NFILENAME)) {
++$cnt;
$NFILENAME = $NFILE_NAME . '_' . $cnt . $NFILE_EXT;
}
Expand Down Expand Up @@ -289,7 +289,7 @@ function rex_mediapool_syncFile($physical_filename, $category_id, $title, $files
{
$abs_file = rex_path::media($physical_filename);

if (!file_exists($abs_file)) {
if (!is_file($abs_file)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/addons/mediapool/lib/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public function getExtension()
*/
public function fileExists()
{
return file_exists(rex_path::media($this->getFileName()));
return is_file(rex_path::media($this->getFileName()));
}

// allowed filetypes
Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/addons/mediapool/pages/media.detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
$width = '';
}

if (!file_exists(rex_path::media($fname))) {
if (!is_file(rex_path::media($fname))) {
$sidebar = '<i class="rex-mime rex-mime-error"></i><span class="sr-only">' . $fname . '</span>';
} else {
$sidebar = '
Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/addons/mediapool/pages/media.list.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
}

// wenn datei fehlt
if (!file_exists(rex_path::media($file_name))) {
if (!is_file(rex_path::media($file_name))) {
$thumbnail = '<i class="rex-mime rex-mime-error" title="' . rex_i18n::msg('pool_file_does_not_exist') . '"></i><span class="sr-only">' . $file_name . '</span>';
} else {
$file_ext = substr(strrchr($file_name, '.'), 1);
Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/addons/mediapool/pages/sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// Extra - filesize/width/height DB-Filesystem Sync
foreach ($db_files as $db_file) {
$path = rex_path::media($db_file['filename']);
if (!file_exists($path)) {
if (!is_file($path)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/addons/phpmailer/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@

$oldBackUpFolder = rex_path::addonData('phpmailer', 'mail_backup');
$logFolder = rex_path::addonData('phpmailer', 'mail_log');
if (file_exists($oldBackUpFolder) && !file_exists($logFolder)) {
if (is_dir($oldBackUpFolder) && !is_dir($logFolder)) {
rename($oldBackUpFolder, $logFolder);
}
2 changes: 1 addition & 1 deletion redaxo/src/addons/phpmailer/lib/mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private function archive(): void

$count = 1;
$archiveFile = $dir.'/'.date('Y-m-d_H_i_s').'.html';
while (file_exists($archiveFile)) {
while (is_file($archiveFile)) {
$archiveFile = $dir.'/'.date('Y-m-d_H_i_s').'_'.(++$count).'.html';
}

Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/addons/structure/lib/structure_element.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static function getClassVars()

$startId = rex_article::getSiteStartArticleId();
$file = rex_path::addonCache('structure', $startId . '.1.article');
if (!rex::isBackend() && file_exists($file)) {
if (!rex::isBackend() && is_file($file)) {
// da getClassVars() eine statische Methode ist, können wir hier nicht mit $this->getId() arbeiten!
$genVars = rex_file::getCache($file);
unset($genVars['last_update_stamp']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getFile()

$file = rex_template_cache::getPath($this->id);

if (!file_exists($file)) {
if (!is_file($file)) {
rex_template_cache::generate($this->id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function getArticle($curctype = -1)
$article_content_file = rex_path::addonCache('structure', $this->article_id . '.' . $this->clang . '.content');

$generated = true;
if (!file_exists($article_content_file)) {
if (!is_file($article_content_file)) {
$generated = rex_content_service::generateArticleContent($this->article_id, $this->clang);
if (true !== $generated) {
// fehlermeldung ausgeben
Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/addons/structure/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
foreach ($addon->getInstalledPlugins() as $plugin) {
$file = __DIR__.'/plugins/'.$plugin->getName().'/install.php';

if (file_exists($file)) {
if (is_file($file)) {
$plugin->includeFile($file);
}
}
2 changes: 1 addition & 1 deletion redaxo/src/core/lib/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private static function findClasses($path)
*/
$contents = @php_strip_whitespace($path);
if (!$contents) {
if (!file_exists($path)) {
if (!is_file($path)) {
$message = 'File at "%s" does not exist, check your classmap definitions';
} elseif (!is_readable($path)) {
$message = 'File at "%s" is not readable, check its permissions';
Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/core/lib/be/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private static function pageAddProperties(rex_be_page $page, array $properties,

case 'path':
case 'subpath':
if (file_exists($path = $package->getPath($value))) {
if (is_file($path = $package->getPath($value))) {
$value = $path;
}
// no break
Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/core/lib/clang/clang.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private static function checkCache()
}

$file = rex_path::coreCache('clang.cache');
if (!file_exists($file)) {
if (!is_file($file)) {
rex_clang_service::generateCache();
}
foreach (rex_file::getCache($file) as $id => $data) {
Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/core/lib/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ protected static function load()
private static function loadFromFile()
{
// delete cache-file, will be regenerated on next request
if (file_exists(self::$cacheFile)) {
if (is_file(self::$cacheFile)) {
self::$data = rex_file::getCache(self::$cacheFile);
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions redaxo/src/core/lib/console/assets_sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private function sync(SymfonyStyle $io, $folder1, $folder2)
$hasError = true;
$io->text("<error>Not readable:</error> <comment>$f1FileShort</comment>");
}
if (file_exists($f2File) && !is_writable($f2File)) {
if (is_file($f2File) && !is_writable($f2File)) {
++$errored;
$hasError = true;
$io->text("<error>Not writable:</error> <comment>$f2FileShort</comment>");
Expand All @@ -115,7 +115,7 @@ private function sync(SymfonyStyle $io, $folder1, $folder2)
continue;
}

if (!file_exists($f2File)) {
if (!is_file($f2File)) {
rex_file::copy($f1File, $f2File);
++$created;
if ($io->isVerbose()) {
Expand Down
Loading

0 comments on commit 3ee969f

Please sign in to comment.