summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-06-28 21:59:01 +0200
committerBart Visscher <bartv@thisnet.nl>2012-06-28 22:11:04 +0200
commit02e4e0e08f39bfb59a7bd8e4a538d6715897af2b (patch)
tree53b2fea136869a72c686aef7743769980c9f473e /apps
parentbf09edcbf1775115067611b85b954fbabad74ba3 (diff)
downloadnextcloud-server-02e4e0e08f39bfb59a7bd8e4a538d6715897af2b.tar.gz
nextcloud-server-02e4e0e08f39bfb59a7bd8e4a538d6715897af2b.zip
Gallery: Get all the image information for a directory at once
Diffstat (limited to 'apps')
-rw-r--r--apps/gallery/lib/managers.php24
1 files changed, 20 insertions, 4 deletions
diff --git a/apps/gallery/lib/managers.php b/apps/gallery/lib/managers.php
index fcce3f40e23..17eb741a660 100644
--- a/apps/gallery/lib/managers.php
+++ b/apps/gallery/lib/managers.php
@@ -4,6 +4,7 @@ namespace OC\Pictures;
class DatabaseManager {
private static $instance = null;
+ protected $cache = array();
const TAG = 'DatabaseManager';
public static function getInstance() {
@@ -12,13 +13,27 @@ class DatabaseManager {
return self::$instance;
}
+ protected function getPathData($path) {
+ $stmt = \OCP\DB::prepare('SELECT * FROM *PREFIX*pictures_images_cache
+ WHERE uid_owner LIKE ? AND path like ? AND path not like ?');
+ $path_match = $path.'/%';
+ $path_notmatch = $path.'/%/%';
+ $result = $stmt->execute(array(\OCP\USER::getUser(), $path_match, $path_notmatch));
+ $this->cache[$path] = array();
+ while (($row = $result->fetchRow()) != false) {
+ $this->cache[$path][$row['path']] = $row;
+ }
+ }
+
public function getFileData($path) {
$gallery_path = \OCP\Config::getSystemValue( 'datadirectory' ).'/'.\OC_User::getUser().'/gallery';
$path = $gallery_path.$path;
- $stmt = \OCP\DB::prepare('SELECT * FROM *PREFIX*pictures_images_cache WHERE uid_owner LIKE ? AND path = ?');
- $result = $stmt->execute(array(\OCP\USER::getUser(), $path));
- if (($row = $result->fetchRow()) != false) {
- return $row;
+ $dir = dirname($path);
+ if (!isset($this->cache[$dir])) {
+ $this->getPathData($dir);
+ }
+ if (isset($this->cache[$dir][$path])) {
+ return $this->cache[$dir][$path];
}
$image = new \OC_Image();
if (!$image->loadFromFile($path)) {
@@ -28,6 +43,7 @@ class DatabaseManager {
$stmt->execute(array(\OCP\USER::getUser(), $path, $image->width(), $image->height()));
$ret = array('path' => $path, 'width' => $image->width(), 'height' => $image->height());
unset($image);
+ $this->cache[$dir][$path] = $ret;
return $ret;
}