diff --git a/lib/Service/MyMapsService.php b/lib/Service/MyMapsService.php index 36fc19945..6770d1670 100644 --- a/lib/Service/MyMapsService.php +++ b/lib/Service/MyMapsService.php @@ -38,14 +38,10 @@ class MyMapsService { private $logger; private $root; - private ICacheFactory $cacheFactory; - private \OCP\ICache $myMapsPathsCache; - public function __construct (ILogger $logger, IRootFolder $root, ICacheFactory $cacheFactory) { + public function __construct (ILogger $logger, IRootFolder $root) { $this->logger = $logger; $this->root = $root; - $this->cacheFactory = $cacheFactory; - $this->myMapsPathsCache = $this->cacheFactory->createDistributed('maps:myMaps-paths'); } public function addMyMap($newName, $userId, $counter=0) { @@ -105,28 +101,9 @@ public function addMyMap($newName, $userId, $counter=0) { "sharePermissions"=>$mapFolder->getPermissions(), ] ]; - $MyMaps = $this->myMapsPathsCache->get($userId); - if ($MyMaps !== null) { - $MyMaps[] = $MyMap; - $this->myMapsPathsCache->set($userId, $MyMaps, 60 * 60 * 24 ); - } return $MyMap; } - private function updateMyMapsCache($userId): array{ - $userFolder = $this->root->getUserFolder($userId); - $MyMaps = []; - $MyMapsNodes = $userFolder->search(new SearchQuery( - new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', 'application/x-nextcloud-maps'), - 0, 0, [])); - - foreach ($MyMapsNodes as $node) { - $MyMaps[] = $this->node2MyMap($node, $userFolder); - } - $this->myMapsPathsCache->set($userId, $MyMaps, 60 * 60 * 24); - return $MyMaps; - } - private function node2MyMap($node, $userFolder):array{ $mapData = json_decode($node->getContent(), true); if (isset($mapData["name"])) { @@ -168,17 +145,18 @@ private function node2MyMap($node, $userFolder):array{ } public function getAllMyMaps($userId){ + $userFolder = $this->root->getUserFolder($userId); + $MyMaps = []; + $MyMapsNodes = $userFolder->search(new SearchQuery( + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', 'application/x-nextcloud-maps'), + 0, 0, [])); - $MyMaps = []; - try { - $MyMaps = null; // $this->myMapsPathsCache->get($userId); - if ($MyMaps === null) { - $MyMaps = $this->updateMyMapsCache($userId); + foreach ($MyMapsNodes as $node) { + if ($node->getName() === ".maps") { + $MyMaps[] = $this->node2MyMap($node, $userFolder); } - } catch (InvalidPathException | NotFoundException | NotPermittedException | NoUserException $e) { - $this->logger->error($e->getMessage()); } - return $MyMaps; + return $MyMaps; } public function updateMyMap($id, $values, $userId) { @@ -205,15 +183,6 @@ public function updateMyMap($id, $values, $userId) { } } $file->putContent(json_encode($mapData,JSON_PRETTY_PRINT)); - $MyMaps = $this->myMapsPathsCache->get($userId); - if ($MyMaps !== null) { - $MyMap = $this->node2MyMap($file, $userFolder); - $oldKey = array_key_first(array_filter($MyMaps, function ($m) use ($id) { - return $m['id']===$id; - })); - $MyMaps[$oldKey] = $MyMap; - $this->myMapsPathsCache->set($userId, $MyMaps, 60 * 60 * 24); - } if ($renamed) { if ($userFolder->nodeExists('/Maps')) { $mapsFolder = $userFolder->get('/Maps'); @@ -230,14 +199,6 @@ public function updateMyMap($id, $values, $userId) { public function deleteMyMap($id, $userId) { $userFolder = $this->root->getUserFolder($userId); - $MyMaps = $this->myMapsPathsCache->get($userId); - if ($MyMaps !== null) { - $oldKey = array_key_first(array_filter($MyMaps, function ($m) use ($id) { - return $m['id']===$id; - })); - unset($MyMaps[$oldKey]); - $this->myMapsPathsCache->set($userId, $MyMaps, 60 * 60 * 24); - } $folders = $userFolder->getById($id); $folder = array_shift($folders);