]> source.dussan.org Git - nextcloud-server.git/commitdiff
cache the media collection between page loads
authorRobin Appelman <icewind1991@gmail.com>
Sun, 31 Jul 2011 22:18:09 +0000 (00:18 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Sun, 31 Jul 2011 22:18:09 +0000 (00:18 +0200)
apps/media/ajax/api.php

index bb86c13f2875f088a73e8479be3d58658bc8e39a..b8883166732c844bd8258360d85f25c0348bc33f 100644 (file)
@@ -56,6 +56,7 @@ OC_MEDIA_COLLECTION::$uid=OC_User::getUser();
 if($arguments['action']){
        switch($arguments['action']){
                case 'delete':
+                       unset($_SESSION['collection']);
                        $path=$arguments['path'];
                        OC_MEDIA_COLLECTION::deleteSongByPath($path);
                        $paths=explode(PATH_SEPARATOR,OC_Preferences::getValue(OC_User::getUser(),'media','paths',''));
@@ -64,17 +65,21 @@ if($arguments['action']){
                                OC_Preferences::setValue(OC_User::getUser(),'media','paths',implode(PATH_SEPARATOR,$paths));
                        }
                case 'get_collection':
-                       $artists=OC_MEDIA_COLLECTION::getArtists();
-                       foreach($artists as &$artist){
-                               $artist['albums']=OC_MEDIA_COLLECTION::getAlbums($artist['artist_id']);
-                               foreach($artist['albums'] as &$album){
-                                       $album['songs']=OC_MEDIA_COLLECTION::getSongs($artist['artist_id'],$album['album_id']);
+                       if(!isset($_SESSION['collection'])){
+                               $artists=OC_MEDIA_COLLECTION::getArtists();
+                               foreach($artists as &$artist){
+                                       $artist['albums']=OC_MEDIA_COLLECTION::getAlbums($artist['artist_id']);
+                                       foreach($artist['albums'] as &$album){
+                                               $album['songs']=OC_MEDIA_COLLECTION::getSongs($artist['artist_id'],$album['album_id']);
+                                       }
                                }
+
+                               $_SESSION['collection']=json_encode($artists);
                        }
-                       
-                       echo json_encode($artists);
+                       echo $_SESSION['collection'];
                        break;
                case 'scan':
+                       unset($_SESSION['collection']);
                        OC_DB::beginTransaction();
                        set_time_limit(0); //recursive scan can take a while
                        $path=$arguments['path'];
@@ -90,6 +95,7 @@ if($arguments['action']){
                        flush();
                        break;
                case 'scanFile':
+                       unset($_SESSION['collection']);
                        echo (OC_MEDIA_SCANNER::scanFile($arguments['path']))?'true':'false';
                        break;
                case 'get_artists':