Thanks to visit codestin.com
Credit goes to github.com

Skip to content

perf(files_external/s3): skip download in truncating modes in fopen#58675

Open
joshtrichards wants to merge 1 commit intomasterfrom
jtr/perf-external-s3-truncating-writes-no-dl
Open

perf(files_external/s3): skip download in truncating modes in fopen#58675
joshtrichards wants to merge 1 commit intomasterfrom
jtr/perf-external-s3-truncating-writes-no-dl

Conversation

@joshtrichards
Copy link
Member

@joshtrichards joshtrichards commented Mar 2, 2026

  • Resolves: #

Summary

Pre-filling the temp file with remote content is only necessary for modes that do NOT truncate but allow both reading and writing (such as 'r+', 'a+', 'c+'). Truncating modes like 'w+' don't need the original file. Therefore downloading is a useless operation and skipping the download is more efficient.

We already do it this way when using S3 as Primary Storage:

case 'w':
case 'wb':
case 'w+':
case 'wb+':
$dirName = dirname($path);
$parentExists = $this->is_dir($dirName);
if (!$parentExists) {
return false;
}
$tmpFile = Server::get(ITempManager::class)->getTemporaryFile($ext);
$handle = fopen($tmpFile, $mode);
return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile): void {
$this->writeBack($tmpFile, $path);
unlink($tmpFile);
});

TODO

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Pre-filling the temp file with remote content is only necessary for modes that do NOT truncate but allow both reading and writing (such as 'r+', 'a+', 'c+'). Truncating modes like 'w+' don't need the original file, and skipping the download is more efficient.

Signed-off-by: Josh <[email protected]>
@joshtrichards joshtrichards added this to the Nextcloud 34 milestone Mar 2, 2026
@joshtrichards joshtrichards requested a review from a team as a code owner March 2, 2026 16:42
@joshtrichards joshtrichards requested review from artonge, leftybournes, nfebe and sorbaugh and removed request for a team March 2, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant