summaryrefslogtreecommitdiffstats
path: root/lib/private/files/cache
diff options
context:
space:
mode:
authorVictor Dubiniuk <victor.dubiniuk@gmail.com>2013-10-04 16:17:19 +0300
committerVictor Dubiniuk <victor.dubiniuk@gmail.com>2013-10-04 16:17:19 +0300
commit65750cb2448af6d543132819ea7f7ee9720b825c (patch)
tree338284a5c5aa837bdbb1f7aabc8f39375131df8d /lib/private/files/cache
parent800bf0769ff4ea63c5dcc77eaaf1bce669b73d13 (diff)
downloadnextcloud-server-65750cb2448af6d543132819ea7f7ee9720b825c.tar.gz
nextcloud-server-65750cb2448af6d543132819ea7f7ee9720b825c.zip
Load all mimetypes in one go
Diffstat (limited to 'lib/private/files/cache')
-rw-r--r--lib/private/files/cache/cache.php37
1 files changed, 20 insertions, 17 deletions
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php
index e69733727af..852036929dd 100644
--- a/lib/private/files/cache/cache.php
+++ b/lib/private/files/cache/cache.php
@@ -64,30 +64,33 @@ class Cache {
* @return int
*/
public function getMimetypeId($mime) {
+ if (empty($this->mimetypeIds)) {
+ $this->loadMimetypes();
+ }
+
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');
- }
+ $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;
- }
+ }
+
return $this->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($this->mimetypes)) {
+ $this->loadMimetypes();
}
- return $this->mimetypes[$id];
+
+ return isset($this->mimetypes[$id]) ? $this->mimetypes[$id] : null;
+ }
+
+ protected function loadMimetypes(){
+ $result = \OC_DB::executeAudited('SELECT `id`, `mimetype` FROM `*PREFIX*mimetypes`', array());
+ while ($result && $row = $result->fetchRow()) {
+ $this->mimetypeIds[$row['mimetype']] = $row['id'];
+ $this->mimetypes[$row['id']] = $row['mimetype'];
+ }
}
/**