Hi,

deleting a directory with a tree of some subdirs below is very slow in the current implementation. It is rather serious imo, because people will not wait for the script to finish and start to "click around".

Find attached a patch that should make deletion way faster. I'd like to ask you, probably Robin, to review and commit if you like.

regards,

Klaas

diff --git a/lib/filecache.php b/lib/filecache.php
index 9ec307c..0d663bd 100644
--- a/lib/filecache.php
+++ b/lib/filecache.php
@@ -172,6 +172,38 @@ class OC_FileCache{
 	}
 
 	/**
+	 * return array of child ids of a directory
+	 * @param query object $query
+	 * @param int $file
+	 * @param string root (optional)
+	 * @return array of childids
+	 */
+	public static function directoryChildIds($query, $id, $root='') {
+	    $result=$query->execute(array($id));
+	    $children=array();
+	    $re=array();
+
+            OC_Log::write('files','directoryChildIds(): incoming id: '.$id,OC_Log::DEBUG);
+	    while($row=$result->fetchRow()) {
+		$children[] = $row['id'];
+	    }
+	    if( count($children)>0 ) {
+		$re=$children;
+		$kidskids = array();
+		foreach($children as $kid) {
+		    OC_Log::write('files','directoryChildIds(): Kid: '.$kid,OC_Log::DEBUG);
+		    $kidskids=array_merge($kidskids, self::directoryChildIds($query, $kid, $root));
+		}
+	    
+		if(count($kidskids) > 0) {
+		    OC_Log::write('files','directoryChildIds(): ('.implode(', ', $kidskids).')',OC_Log::DEBUG);
+		    $re=array_merge($children, $kidskids);
+		}
+	    }
+	    return $re;
+	}
+	
+	/**
 	 * delete info from the cache
 	 * @param string/int $file
 	 * @param string root (optional)
@@ -188,12 +220,14 @@ class OC_FileCache{
 			self::delete(self::getFileId($path));
 		}elseif($file!=-1){
 			$query=OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE parent=?');
-			$result=$query->execute(array($file));
-			while($child=$result->fetchRow()){
-				self::delete(intval($child['id']));
-			}
-			$query=OC_DB::prepare('DELETE FROM *PREFIX*fscache WHERE id=?');
-			$query->execute(array($file));
+
+			$ids=self::directoryChildIds($query, $file, $root);
+			$ids[] = $file;
+			$idStr=implode(',', $ids);
+			OC_Log::write('files','delete(): '.$idStr, OC_Log::DEBUG);
+	    
+			$query=OC_DB::prepare('DELETE FROM *PREFIX*fscache WHERE id in ('. $idStr . ')');
+			$query->execute();
 		}
 	}
 	
_______________________________________________
Owncloud mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/owncloud

Reply via email to