From 6d125ec400dec690e075c46d8a8f45a24a953aa0 Mon Sep 17 00:00:00 2001 From: Mat Dave Jones Date: Mon, 2 Oct 2023 16:59:28 -0500 Subject: [PATCH] S3 Speed Up (#16438) * remove functions that require PHP to interact with objects directly, in an effort to dramatically speed up S3 response times. * fix PHPCS * fix type conflict --- .../Revolution/Sources/modS3MediaSource.php | 132 +++++++++++++++++- 1 file changed, 127 insertions(+), 5 deletions(-) diff --git a/core/src/Revolution/Sources/modS3MediaSource.php b/core/src/Revolution/Sources/modS3MediaSource.php index 26560981d63..7ab7cca326c 100644 --- a/core/src/Revolution/Sources/modS3MediaSource.php +++ b/core/src/Revolution/Sources/modS3MediaSource.php @@ -200,6 +200,9 @@ protected function getListDirContextMenu() { $menu = parent::getListDirContextMenu(); foreach ($menu as $k => $v) { + if (gettype($v) !== 'array') { + continue; + } if ($v['handler'] === 'this.renameDirectory') { unset($menu[$k]); $menu = array_values($menu); @@ -373,7 +376,6 @@ public function getContainerList($path) ) { $cls = $this->getExtJSDirClasses(); $dirNames[] = strtoupper($file_name); - $visibility = true; $directories[$file_name] = [ 'id' => $id, 'sid' => $this->get('id'), @@ -384,12 +386,11 @@ public function getContainerList($path) 'leaf' => false, 'path' => $object['path'], 'pathRelative' => $object['path'], - 'menu' => [], + 'menu' => [ + 'items' => $this->getListDirContextMenu(), + ], 'visibility' => true ]; - $directories[$file_name]['menu'] = [ - 'items' => $this->getListDirContextMenu(), - ]; } elseif ( $object['type'] === 'file' && !$properties['hideFiles'] && @@ -648,4 +649,125 @@ public function setVisibility($path, $visibility) // S3 Set visibility always returns false return false; } + + protected function getImageDimensions($path, $ext) + { + return false; + } + + protected function isFileBinary($file) + { + $binary_extensions = [ + 'css', + 'csv', + 'htm', + 'html', + 'ics', + 'ini', + 'js', + 'json', + 'less', + 'log', + 'md', + 'mjs', + 'php', + 'sh', + 'scss', + 'sql', + 'tpl', + 'tsv', + 'txt', + 'xml', + ]; + foreach ($binary_extensions as $a) { + if (stripos($file, $a) !== false) { + return true; + } + } + return false; + } + + protected function isFileImage($file, $image_extensions = []) + { + foreach ($image_extensions as $a) { + if (stripos($file, $a) !== false) { + return true; + } + } + return false; + } + + + /** + * @param string $path + * @param string $ext + * @param array $image_extensions + * @param array $bases + * @param array $properties + * + * @return array + */ + protected function buildFileBrowserViewList($path, $ext, $image_extensions, $bases, $properties) + { + $editAction = $this->getEditActionId(); + + $page = null; + if (!$this->isFileBinary($path)) { + $page = !empty($editAction) + ? '?a=' . $editAction . + '&file=' . $path . + '&wctx=' . $this->ctx->get('key') . + '&source=' . $this->get('id') + : null; + } + + $width = $this->ctx->getOption('filemanager_image_width', 800); + $height = $this->ctx->getOption('filemanager_image_height', 600); + + $thumb_width = $this->ctx->getOption('filemanager_thumb_width', 100); + $thumb_height = $this->ctx->getOption('filemanager_thumb_height', 80); + + $preview = 0; + if ($this->isFileImage($path, $image_extensions)) { + $preview = 1; + $preview_image_info = $this->buildManagerImagePreview($path, $ext, $width, $height, $bases, $properties); + } + + $visibility = $this->visibility_files ? $this->getVisibility($path) : false; + + $lastmod = 0; + $size = 0; + $file_list = [ + 'id' => $path, + 'sid' => $this->get('id'), + 'name' => basename($path), + 'cls' => 'icon-' . $ext, + // preview + 'preview' => $preview, + 'image' => $preview_image_info['src'] ?? '', + // thumb + 'thumb' => $preview_image_info['src'] ?? '', + 'thumb_width' => $thumb_width, + 'thumb_height' => $thumb_height, + + 'url' => $path, + 'relativeUrl' => ltrim($path, DIRECTORY_SEPARATOR), + 'fullRelativeUrl' => rtrim($bases['url']) . ltrim($path, DIRECTORY_SEPARATOR), + 'ext' => $ext, + 'pathname' => $path, + 'pathRelative' => rawurlencode($path), + + 'lastmod' => $lastmod, + 'disabled' => false, + 'leaf' => true, + 'page' => $page, + 'size' => $size, + 'menu' => $this->getListFileContextMenu($path, !empty($page)), + ]; + if ($this->visibility_files && $visibility) { + $file_list['visibility'] = $visibility; + } + + return $file_list; + } }