summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFrank Karlitschek <frank@owncloud.org>2013-10-05 02:24:38 -0700
committerFrank Karlitschek <frank@owncloud.org>2013-10-05 02:24:38 -0700
commit4bce2f8b85dbbe8fb25dc64b2bc049342d2d1ae7 (patch)
treeb4fc24cb8577687d927b900be8db98adf62c024b /lib
parentcc1e69c1902a9cf6c6c68cdaa3f1eead09ca7a5c (diff)
parent8da1aac1d0065e2da6841bf98b8bb60fcefa14c8 (diff)
downloadnextcloud-server-4bce2f8b85dbbe8fb25dc64b2bc049342d2d1ae7.tar.gz
nextcloud-server-4bce2f8b85dbbe8fb25dc64b2bc049342d2d1ae7.zip
Merge pull request #5123 from owncloud/cache_mimetypes
Load all mimetypes in one go
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/cache/cache.php47
1 files changed, 26 insertions, 21 deletions
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php
index e69733727af..364a50d377c 100644
--- a/lib/private/files/cache/cache.php
+++ b/lib/private/files/cache/cache.php
@@ -34,8 +34,8 @@ class Cache {
*/
private $storageCache;
- private $mimetypeIds = array();
- private $mimetypes = array();
+ private static $mimetypeIds = array();
+ private static $mimetypes = array();
/**
* @param \OC\Files\Storage\Storage|string $storage
@@ -64,30 +64,35 @@ class Cache {
* @return int
*/
public function getMimetypeId($mime) {
- if (!isset($this->mimetypeIds[$mime])) {
- $result = \OC_DB::executeAudited('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?', array($mime));
- if ($row = $result->fetchRow()) {
- $this->mimetypeIds[$mime] = $row['id'];
- } else {
- $result = \OC_DB::executeAudited('INSERT INTO `*PREFIX*mimetypes`(`mimetype`) VALUES(?)', array($mime));
- $this->mimetypeIds[$mime] = \OC_DB::insertid('*PREFIX*mimetypes');
- }
- $this->mimetypes[$this->mimetypeIds[$mime]] = $mime;
+ if (empty(self::$mimetypeIds)) {
+ $this->loadMimetypes();
}
- return $this->mimetypeIds[$mime];
+
+ if (!isset(self::$mimetypeIds[$mime])) {
+ $result = \OC_DB::executeAudited('INSERT INTO `*PREFIX*mimetypes`(`mimetype`) VALUES(?)', array($mime));
+ self::$mimetypeIds[$mime] = \OC_DB::insertid('*PREFIX*mimetypes');
+ self::$mimetypes[self::$mimetypeIds[$mime]] = $mime;
+ }
+
+ return self::$mimetypeIds[$mime];
}
public function getMimetype($id) {
- if (!isset($this->mimetypes[$id])) {
- $sql = 'SELECT `mimetype` FROM `*PREFIX*mimetypes` WHERE `id` = ?';
- $result = \OC_DB::executeAudited($sql, array($id));
- if ($row = $result->fetchRow()) {
- $this->mimetypes[$id] = $row['mimetype'];
- } else {
- return null;
- }
+ if (empty(self::$mimetypes)) {
+ $this->loadMimetypes();
}
- return $this->mimetypes[$id];
+
+ return isset(self::$mimetypes[$id]) ? self::$mimetypes[$id] : null;
+ }
+
+ protected function loadMimetypes(){
+ $result = \OC_DB::executeAudited('SELECT `id`, `mimetype` FROM `*PREFIX*mimetypes`', array());
+ if ($result) {
+ while ($row = $result->fetchRow()) {
+ self::$mimetypeIds[$row['mimetype']] = $row['id'];
+ self::$mimetypes[$row['id']] = $row['mimetype'];
+ }
+ }
}
/**