]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add stat cache to OC_Connector_Sabre_Node and OC_Connector_Sabre_File
authorBart Visscher <bartv@thisnet.nl>
Fri, 8 Jun 2012 18:26:08 +0000 (20:26 +0200)
committerBart Visscher <bartv@thisnet.nl>
Tue, 19 Jun 2012 21:13:21 +0000 (23:13 +0200)
Speeds up access of directories with large number of files.

lib/connector/sabre/file.php
lib/connector/sabre/node.php

index f2efe0a5ac1df94420d7cd7cca94e49961013dbe..3ba1b3355f28266953ea4aea7e9d7ffac994ae5b 100644 (file)
@@ -63,8 +63,8 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
         * @return int
         */
        public function getSize() {
-       
-               return OC_Filesystem::filesize($this->path);
+               $this->stat();
+               return $this->stat_cache['size'];
 
        }
 
index a7d1de8b953e75aab2c1fa5b7557b0916ef52dcd..b9a17e3b392e0a850995ab691ab3a937f18f2bfb 100644 (file)
@@ -29,6 +29,11 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
         * @var string
         */
        protected $path;
+       /**
+        * file stat cache
+        * @var array
+        */
+       protected $stat_cache;
 
        /**
         * Sets up the node, expects a full path name
@@ -77,7 +82,14 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
 
        }
 
-
+       /**
+        * Set the stat cache
+        */
+       protected function stat() {
+               if (!isset($this->stat_cache)) {
+                       $this->stat_cache = OC_Filesystem::stat($this->path);
+               }
+       }
 
        /**
         * Returns the last modification time, as a unix timestamp
@@ -85,8 +97,8 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
         * @return int
         */
        public function getLastModified() {
-
-               return OC_Filesystem::filemtime($this->path);
+               $this->stat();
+               return $this->stat_cache['mtime'];
 
        }