Skip to content

Only load the file to the attachments if it is actually needed#6381

Merged
Cyperghost merged 1 commit into6.1from
6.1-attachment-load-file
Jul 9, 2025
Merged

Only load the file to the attachments if it is actually needed#6381
Cyperghost merged 1 commit into6.1from
6.1-attachment-load-file

Conversation

@Cyperghost
Copy link
Contributor

This ensures that when AttachmentList::loadFiles() is called, the files are not loaded individually from the database. This happens by calling $attachment->fileID, which corresponds to $attachment->__get('fileID').

private function loadFiles(): void
{
$fileIDs = [];
foreach ($this->objects as $attachment) {
if ($attachment->fileID) {
$fileIDs[] = $attachment->fileID;
}
}
if ($fileIDs === []) {
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);
}
foreach ($this->objects as $attachment) {
$file = $files[$attachment->fileID] ?? null;
if ($file !== null) {
$attachment->setFile($file);
}
}
}

…herwise, the file will be loaded individually for each attachment instead of being bundled.
@Cyperghost Cyperghost requested a review from dtdesign July 8, 2025 12:06
@Cyperghost Cyperghost merged commit 21d3468 into 6.1 Jul 9, 2025
8 checks passed
@Cyperghost Cyperghost deleted the 6.1-attachment-load-file branch July 9, 2025 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants