aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Node
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2020-02-16 01:14:52 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2020-02-28 12:55:22 +0100
commit5ca1929e8cbc9beb32783a769e5a127527c1d93e (patch)
tree4721b25d9e07c22e13dcfcc39fa56a4f29cee7fb /lib/private/Files/Node
parentfed86e8382acb84b81e75e43fa9318700d5502ae (diff)
downloadnextcloud-server-5ca1929e8cbc9beb32783a769e5a127527c1d93e.tar.gz
nextcloud-server-5ca1929e8cbc9beb32783a769e5a127527c1d93e.zip
Create SimpleFile only when writing the content
instead of first creating an empty file and then writing the content. This solves the overhead of creating an empty file with the common pattern: ```php $file = $simpleFilder->newFile('foo.txt'); $file->putContent('bar.txt'); ``` roughly halving the number of storage and database operations that need to be done when creating a `SimpleFile`. This is not automatically done with `File` because that has a more complex api which I'm more hesitant to touch. Instead the `Folder::newFile` api has been extended to accept the content for the new file. In my local testing, the overhead of first creating an empty file took about 20% of the time for preview generation Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files/Node')
-rw-r--r--lib/private/Files/Node/Folder.php10
-rw-r--r--lib/private/Files/Node/LazyRoot.php2
-rw-r--r--lib/private/Files/Node/NonExistingFolder.php2
3 files changed, 10 insertions, 4 deletions
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php
index 1267c818668..727b08e9335 100644
--- a/lib/private/Files/Node/Folder.php
+++ b/lib/private/Files/Node/Folder.php
@@ -173,15 +173,21 @@ class Folder extends Node implements \OCP\Files\Folder {
/**
* @param string $path
+ * @param string | resource | null $content
* @return \OC\Files\Node\File
* @throws \OCP\Files\NotPermittedException
*/
- public function newFile($path) {
+ public function newFile($path, $content = null) {
if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) {
$fullPath = $this->getFullPath($path);
$nonExisting = new NonExistingFile($this->root, $this->view, $fullPath);
$this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]);
- if (!$this->view->touch($fullPath)) {
+ if ($content !== null) {
+ $result = $this->view->file_put_contents($fullPath, $content);
+ } else {
+ $result = $this->view->touch($fullPath);
+ }
+ if (!$result) {
throw new NotPermittedException('Could not create path');
}
$node = new File($this->root, $this->view, $fullPath);
diff --git a/lib/private/Files/Node/LazyRoot.php b/lib/private/Files/Node/LazyRoot.php
index 76868cfa5cd..8076c3b4f6a 100644
--- a/lib/private/Files/Node/LazyRoot.php
+++ b/lib/private/Files/Node/LazyRoot.php
@@ -394,7 +394,7 @@ class LazyRoot implements IRootFolder {
/**
* @inheritDoc
*/
- public function newFile($path) {
+ public function newFile($path, $content = null) {
return $this->__call(__FUNCTION__, func_get_args());
}
diff --git a/lib/private/Files/Node/NonExistingFolder.php b/lib/private/Files/Node/NonExistingFolder.php
index 30470740495..65af837da43 100644
--- a/lib/private/Files/Node/NonExistingFolder.php
+++ b/lib/private/Files/Node/NonExistingFolder.php
@@ -139,7 +139,7 @@ class NonExistingFolder extends Folder {
throw new NotFoundException();
}
- public function newFile($path) {
+ public function newFile($path, $content = null) {
throw new NotFoundException();
}