]> source.dussan.org Git - nextcloud-server.git/commitdiff
divide ids into chunks of 1k
authorJörn Friedrich Dreyer <jfd@butonic.de>
Wed, 31 Jul 2013 13:13:00 +0000 (15:13 +0200)
committerVictor Dubiniuk <victor.dubiniuk@gmail.com>
Thu, 19 Sep 2013 18:08:32 +0000 (21:08 +0300)
apps/files_sharing/lib/cache.php

index 28e3cbdb2e18010360f9f959567d03d9a58dc1e8..6386f1d2c60a391ee7ae60b1629c31c488efc540 100644 (file)
@@ -239,16 +239,25 @@ class Shared_Cache extends Cache {
                        }
                        
                }
-               $placeholders = join(',', array_fill(0, count($ids), '?'));
-               
-               $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag`
-                               FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `fileid` IN (' . $placeholders . ')';
-               $result = \OC_DB::executeAudited($sql, array_merge(array($pattern), $ids));
+
                $files = array();
-               while ($row = $result->fetchRow()) {
-                       $row['mimetype'] = $this->getMimetype($row['mimetype']);
-                       $row['mimepart'] = $this->getMimetype($row['mimepart']);
-                       $files[] = $row;
+               
+               // divide into 1k chunks
+               $chunks = array_chunk($ids, 1000);
+               
+               foreach ($chunks as $chunk) {
+                       $placeholders = join(',', array_fill(0, count($chunk), '?'));
+
+                       $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag`
+                                       FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `fileid` IN (' . $placeholders . ')';
+                       
+                       $result = \OC_DB::executeAudited($sql, array_merge(array($pattern), $chunk));
+                       
+                       while ($row = $result->fetchRow()) {
+                               $row['mimetype'] = $this->getMimetype($row['mimetype']);
+                               $row['mimepart'] = $this->getMimetype($row['mimepart']);
+                               $files[] = $row;
+                       }
                }
                return $files;
        }