namespace wcf\acp\page;
-use wcf\data\file\FileList;
use wcf\data\user\group\UserGroup;
use wcf\data\user\option\ViewableUserOption;
use wcf\data\user\User;
use wcf\data\user\UserProfile;
use wcf\page\SortablePage;
use wcf\system\cache\builder\UserOptionCacheBuilder;
+use wcf\system\cache\runtime\FileRuntimeCache;
use wcf\system\clipboard\ClipboardHandler;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\event\EventHandler;
}
}
- $fileList = new FileList();
- $fileList->loadThumbnails = true;
- $fileList->setObjectIDs($avatarFileIDs);
- $fileList->readObjects();
- $avatarFiles = $fileList->getObjects();
+ FileRuntimeCache::getInstance()->cacheObjectIDs($avatarFileIDs);
// get special columns
foreach ($this->users as $user) {
- if ($user->avatarFileID !== null) {
- $user->setFileAvatar($avatarFiles[$user->avatarFileID]);
- }
-
foreach ($this->columns as $column) {
switch ($column) {
case 'email':
namespace wcf\data\attachment;
use wcf\data\DatabaseObjectList;
-use wcf\data\file\FileList;
-use wcf\data\file\thumbnail\FileThumbnailList;
+use wcf\system\cache\runtime\FileRuntimeCache;
/**
* Represents a list of attachments.
return;
}
- $fileList = new FileList();
- $fileList->getConditionBuilder()->add("fileID IN (?)", [$fileIDs]);
- $fileList->readObjects();
- $files = $fileList->getObjects();
-
- $thumbnailList = new FileThumbnailList();
- $thumbnailList->getConditionBuilder()->add("fileID IN (?)", [$fileIDs]);
- $thumbnailList->readObjects();
- foreach ($thumbnailList as $thumbnail) {
- $files[$thumbnail->fileID]->addThumbnail($thumbnail);
- }
+ FileRuntimeCache::getInstance()->cacheObjectIDs($fileIDs);
foreach ($this->objects as $attachment) {
- $file = $files[$attachment->fileID] ?? null;
+ $file = FileRuntimeCache::getInstance()->getObject($attachment->fileID) ?? null;
if ($file !== null) {
$attachment->setFile($file);
}
use wcf\data\DatabaseObjectEditor;
use wcf\data\file\temporary\FileTemporary;
use wcf\data\file\thumbnail\FileThumbnailEditor;
-use wcf\data\file\thumbnail\FileThumbnailList;
use wcf\system\file\processor\FileProcessor;
use wcf\system\image\ImageHandler;
use wcf\util\ExifUtil;
public static function deleteAll(array $objectIDs = [])
{
$fileList = new FileList();
+ $fileList->loadThumbnails = true;
$fileList->getConditionBuilder()->add("fileID IN (?)", [$objectIDs]);
$fileList->readObjects();
$files = $fileList->getObjects();
return 0;
}
- $thumbnailList = new FileThumbnailList();
- $thumbnailList->getConditionBuilder()->add("fileID IN (?)", [$objectIDs]);
- $thumbnailList->readObjects();
- foreach ($thumbnailList as $thumbnail) {
- $files[$thumbnail->fileID]->addThumbnail($thumbnail);
- }
-
foreach ($files as $file) {
(new FileEditor($file))->deleteFiles();
}
namespace wcf\data\user;
use wcf\data\DatabaseObjectList;
-use wcf\data\file\FileList;
+use wcf\system\cache\runtime\FileRuntimeCache;
/**
* Contains methods to load avatar files for a list of `UserProfile`.
*/
trait TUserAvatarObjectList
{
- public bool $loadAvatarFiles = true;
-
- protected function loadAvatarFiles(): void
+ protected function cacheAvatarFiles(): void
{
- if (!$this->loadAvatarFiles) {
- return;
- }
-
$avatarFileIDs = [];
foreach ($this->objects as $user) {
if ($user->avatarFileID !== null) {
return;
}
- $fileList = new FileList();
- $fileList->loadThumbnails = true;
- $fileList->setObjectIDs($avatarFileIDs);
- $fileList->readObjects();
- $files = $fileList->getObjects();
-
- foreach ($this->objects as $user) {
- if ($user->avatarFileID !== null) {
- $user->setFileAvatar($files[$user->avatarFileID]);
- }
- }
+ FileRuntimeCache::getInstance()->cacheObjectIDs($avatarFileIDs);
}
}
use wcf\data\DatabaseObjectDecorator;
use wcf\data\file\File;
-use wcf\data\file\FileList;
use wcf\data\ITitledLinkObject;
use wcf\data\trophy\Trophy;
use wcf\data\trophy\TrophyCache;
use wcf\data\user\rank\UserRank;
use wcf\system\cache\builder\UserGroupPermissionCacheBuilder;
use wcf\system\cache\builder\UserRankCacheBuilder;
+use wcf\system\cache\runtime\FileRuntimeCache;
use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\email\Mailbox;
if ($this->avatarFileID !== null) {
$data = UserStorageHandler::getInstance()->getField('avatar', $this->userID);
if ($data === null) {
- $fileList = new FileList();
- $fileList->setObjectIDs([$this->avatarFileID]);
- $fileList->loadThumbnails = true;
- $fileList->readObjects();
-
- $this->avatar = $fileList->getSingleObject();
+ $this->avatar = FileRuntimeCache::getInstance()->getObject($this->avatarFileID);
UserStorageHandler::getInstance()->update(
$this->userID,
parent::readObjects();
- $this->loadAvatarFiles();
+ $this->cacheAvatarFiles();
}
}
{
parent::readObjects();
- $this->loadAvatarFiles();
+ $this->cacheAvatarFiles();
}
}
{
parent::readObjects();
- $this->loadAvatarFiles();
+ $this->cacheAvatarFiles();
}
}
$this->objectIDs = $this->indexToObject;
$this->rewind();
- $this->loadAvatarFiles();
+ $this->cacheAvatarFiles();
}
/**
{
parent::readObjects();
- $this->loadAvatarFiles();
+ $this->cacheAvatarFiles();
}
}
--- /dev/null
+<?php
+
+namespace wcf\system\cache\runtime;
+
+use wcf\data\file\File;
+use wcf\data\file\FileList;
+
+/**
+ * Runtime cache implementation for files with thumbnails.
+ *
+ * @author Olaf Braun
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.2
+ *
+ * @method File[] getCachedObjects()
+ * @method File|null getObject($objectID)
+ * @method File[] getObjects(array $objectIDs)
+ */
+class FileRuntimeCache extends AbstractRuntimeCache
+{
+ /**
+ * @inheritDoc
+ */
+ protected $listClassName = FileList::class;
+
+ #[\Override]
+ protected function getObjectList()
+ {
+ $fileList = new FileList();
+ $fileList->loadThumbnails = true;
+
+ return $fileList;
+ }
+}