From db08637624bb85e90739b3577d056291d4f2da4e Mon Sep 17 00:00:00 2001 From: onli Date: Sat, 1 Aug 2020 20:36:23 +0200 Subject: [PATCH] Improve performance of the media library by caching the file list --- docs/NEWS | 2 ++ include/functions_images.inc.php | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/NEWS b/docs/NEWS index fc52917c..b6f7f2f1 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -1,3 +1,5 @@ + * Improve performance of the media library by caching the file list + Version 2.4-alpha2 () ------------------------------------------------------------------------ * Move MySQL databases from MyIsam and UTF8 to InnoDB and utf8mb4, diff --git a/include/functions_images.inc.php b/include/functions_images.inc.php index ce1cc432..0c4887a6 100644 --- a/include/functions_images.inc.php +++ b/include/functions_images.inc.php @@ -639,6 +639,7 @@ function serendipity_insertImageInDatabase($filename, $directory, $authorid = 0, $image_id = serendipity_db_insert_id('images', 'id'); if ($image_id > 0) { return $image_id; + serendipity_cleanCache(); } return 0; @@ -1948,7 +1949,16 @@ function serendipity_killPath($basedir, $directory = '', $forceDelete = false) { * @return array Array of files/directories */ function serendipity_traversePath($basedir, $dir='', $onlyDirs = true, $pattern = NULL, $depth = 1, $max_depth = NULL, $apply_ACL = false, $aExcludeDirs = NULL) { - + global $serendipity; + + if ($serendipity['useInternalCache']) { + $key = md5($basedir . $dir . $onlyDirs . $pattern . $depth . $max_depth . $apply_ACL . $aExcludeDirs . $serendipity['serendipityUser']); + $files = serendipity_getCacheItem($key); + if ($files && $files !== false) { + return unserialize($files); + } + } + if ($aExcludeDirs === null) { // add _vti_cnf to exclude possible added servers frontpage extensions // add ckeditor/kcfinders .thumb dir to exclude, since no hook @@ -1994,6 +2004,12 @@ function serendipity_traversePath($basedir, $dir='', $onlyDirs = true, $pattern serendipity_directoryACL($files, $apply_ACL); } + if ($serendipity['useInternalCache']) { + $key = md5($basedir . $dir . $onlyDirs . $pattern . $depth . $max_depth . $apply_ACL . $aExcludeDirs . $serendipity['serendipityUser']); + + serendipity_cacheItem($key, serialize($files)); + } + return $files; } @@ -2255,7 +2271,7 @@ function serendipity_renameDir($oldDir, $newDir) { ); serendipity_updateImageInEntries($image['id'], $image); } - + serendipity_cleanCache(); return true; } return false; @@ -2310,7 +2326,7 @@ function serendipity_renameFile($id, $newName, $path = null) { } else { return ' ' . MEDIA_RENAME_FAILED . "\n"; } - + serendipity_cleanCache(); return TRUE; }