]> source.dussan.org Git - nextcloud-server.git/commitdiff
Refactor files' CacheEntry object creation to call cacheEntryFromData() all the time... 3588/head
authorFrédéric Fortier <frederic.fortier@oronospolytechnique.com>
Thu, 23 Feb 2017 01:03:32 +0000 (20:03 -0500)
committerFrédéric Fortier <frederic.fortier@oronospolytechnique.com>
Thu, 23 Feb 2017 01:03:32 +0000 (20:03 -0500)
Signed-off-by: Frédéric Fortier <frederic.fortier@oronospolytechnique.com>
lib/private/Files/Cache/Cache.php

index 689a3ad8096badfc22d9e12fba651bd13dede03e..7e7ebd795a0db61b08592e4658cd044f2bbe65ff 100644 (file)
@@ -197,20 +197,8 @@ class Cache implements ICache {
                                        FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC';
                        $result = $this->connection->executeQuery($sql, [$fileId]);
                        $files = $result->fetchAll();
-                       foreach ($files as &$file) {
-                               $file['mimetype'] = $this->mimetypeLoader->getMimetypeById($file['mimetype']);
-                               $file['mimepart'] = $this->mimetypeLoader->getMimetypeById($file['mimepart']);
-                               if ($file['storage_mtime'] == 0) {
-                                       $file['storage_mtime'] = $file['mtime'];
-                               }
-                               $file['permissions'] = (int)$file['permissions'];
-                               $file['mtime'] = (int)$file['mtime'];
-                               $file['storage_mtime'] = (int)$file['storage_mtime'];
-                               $file['size'] = 0 + $file['size'];
-                               $file['storage'] = (int)$file['storage'];
-                       }
                        return array_map(function (array $data) {
-                               return new CacheEntry($data);
+                               return self::cacheEntryFromData($data, $this->mimetypeLoader);;
                        }, $files);
                } else {
                        return array();
@@ -603,22 +591,18 @@ class Cache implements ICache {
 
                $sql = '
                        SELECT `fileid`, `storage`, `path`, `parent`, `name`,
-                               `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`,
-                               `etag`, `permissions`, `checksum`
+                               `mimetype`, `storage_mtime`, `mimepart`, `size`, `mtime`,
+                                `encrypted`, `etag`, `permissions`, `checksum`
                        FROM `*PREFIX*filecache`
                        WHERE `storage` = ? AND `name` ILIKE ?';
                $result = $this->connection->executeQuery($sql,
                        [$this->getNumericStorageId(), $pattern]
                );
 
-               $files = [];
-               while ($row = $result->fetch()) {
-                       $row['mimetype'] = $this->mimetypeLoader->getMimetypeById($row['mimetype']);
-                       $row['mimepart'] = $this->mimetypeLoader->getMimetypeById($row['mimepart']);
-                       $files[] = $row;
-               }
+               $files = $result->fetchAll();
+
                return array_map(function(array $data) {
-                       return new CacheEntry($data);
+                       return self::cacheEntryFromData($data, $this->mimetypeLoader);
                }, $files);
        }
 
@@ -635,18 +619,15 @@ class Cache implements ICache {
                } else {
                        $where = '`mimepart` = ?';
                }
-               $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum`
+               $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `storage_mtime`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum`
                                FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?';
                $mimetype = $this->mimetypeLoader->getId($mimetype);
                $result = $this->connection->executeQuery($sql, array($mimetype, $this->getNumericStorageId()));
-               $files = array();
-               while ($row = $result->fetch()) {
-                       $row['mimetype'] = $this->mimetypeLoader->getMimetypeById($row['mimetype']);
-                       $row['mimepart'] = $this->mimetypeLoader->getMimetypeById($row['mimepart']);
-                       $files[] = $row;
-               }
+
+               $files = $result->fetchAll();
+
                return array_map(function (array $data) {
-                       return new CacheEntry($data);
+                       return self::cacheEntryFromData($data, $this->mimetypeLoader);
                }, $files);
        }
 
@@ -661,7 +642,7 @@ class Cache implements ICache {
         */
        public function searchByTag($tag, $userId) {
                $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' .
-                       '`mimetype`, `mimepart`, `size`, `mtime`, ' .
+                       '`mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, ' .
                        '`encrypted`, `etag`, `permissions`, `checksum` ' .
                        'FROM `*PREFIX*filecache` `file`, ' .
                        '`*PREFIX*vcategory_to_object` `tagmap`, ' .
@@ -688,12 +669,11 @@ class Cache implements ICache {
                                $tag
                        ]
                );
-               $files = array();
-               while ($row = $result->fetch()) {
-                       $files[] = $row;
-               }
+
+               $files = $result->fetchAll();
+
                return array_map(function (array $data) {
-                       return new CacheEntry($data);
+                       return self::cacheEntryFromData($data, $this->mimetypeLoader);
                }, $files);
        }