diff options
author | Olivier Paroz <github@oparoz.com> | 2015-04-02 12:20:38 +0300 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-06-22 00:47:58 +0300 |
commit | 9e15c7d05cbce52b9afb1057927da629faba65fb (patch) | |
tree | f3ad940eab5596c584ebea9febd3cf267506dbc4 /controller | |
parent | 2a64bdf81545e811172fb4ed0598eb898dd3611d (diff) |
Cache albums as we go along
Fix for #41
Diffstat (limited to 'controller')
-rw-r--r-- | controller/filescontroller.php | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/controller/filescontroller.php b/controller/filescontroller.php index 49ba17a1..9e7e8510 100644 --- a/controller/filescontroller.php +++ b/controller/filescontroller.php @@ -92,22 +92,28 @@ class FilesController extends Controller { * * @param string $location a path representing the current album in the app * @param string $features the list of supported features + * @param string $etag the last known etag in the client * * @return array <string,array<string,string|int>>|Http\JSONResponse */ - public function getFiles($location, $features) { + public function getFiles($location, $features, $etag) { $features = explode(',', $features); $mediaTypesArray = explode(';', $this->request->getParam('mediatypes')); + $files = []; try { /** @var Folder $folderNode */ list($folderPathFromRoot, $folderNode, $locationHasChanged) = $this->filesService->getCurrentFolder(rawurldecode($location), $features); $albumInfo = $this->configService->getAlbumInfo($folderNode, $folderPathFromRoot, $features); - $files = - $this->searchMediaService->getMediaFiles($folderNode, $mediaTypesArray, $features); - $files = $this->fixPaths($files, $folderPathFromRoot); - + + if ($albumInfo['etag'] !== $etag) { + $files = $this->searchMediaService->getMediaFiles( + $folderNode, $mediaTypesArray, $features + ); + $files = $this->fixPaths($files, $folderPathFromRoot); + } + return $this->formatResults($files, $albumInfo, $locationHasChanged); } catch (\Exception $exception) { return $this->error($exception); @@ -136,14 +142,14 @@ class FilesController extends Controller { return $files; } - + /** * Simply builds and returns an array containing the list of files, the album information and * whether the location has changed or not * - * @param $files - * @param $albumInfo - * @param $locationHasChanged + * @param array <string,string|int> $files + * @param array $albumInfo + * @param bool $locationHasChanged * * @return array */ |