]> source.dussan.org Git - nextcloud-server.git/commitdiff
Clear cache on vcard change/delete
authorRoeland Jago Douma <roeland@famdouma.nl>
Wed, 3 May 2017 13:11:26 +0000 (15:11 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Mon, 8 May 2017 09:20:49 +0000 (11:20 +0200)
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
apps/dav/lib/AppInfo/Application.php
apps/dav/lib/CardDAV/ImageExportPlugin.php
apps/dav/lib/CardDAV/PhotoCache.php

index d13f24d369a1dca98c02b1e828a48e4ec01d423f..5d89324d4a9cfde9e921791266ffabaeddf3ad5c 100644 (file)
@@ -112,6 +112,19 @@ class Application extends App {
                        }
                });
 
+               $clearPhotoCache = function($event) {
+                       if ($event instanceof GenericEvent) {
+                               /** @var PhotoCache $p */
+                               $p = $this->getContainer()->query(PhotoCache::class);
+                               $p->delete(
+                                       $event->getArgument('addressBookId'),
+                                       $event->getArgument('cardUri')
+                               );
+                       }
+               };
+               $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
+               $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
+
                $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) {
                        $user = $event->getSubject();
                        $syncService = $this->getContainer()->query(SyncService::class);
index 9d5eba453fb8fa6fed090b4afcba92492adf9b3b..fd9223c855bb4f78b02ba768051d13e16cc9a973 100644 (file)
@@ -103,14 +103,12 @@ class ImageExportPlugin extends ServerPlugin {
                /** @var AddressBook $addressbook */
                $addressbook = $this->server->tree->getNodeForPath($addressbookpath);
 
-               $hash = md5($addressbook->getResourceId() . $node->getName());
-
                $response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate');
                $response->setHeader('Etag', $node->getETag() );
                $response->setHeader('Pragma', 'public');
 
                try {
-                       $file = $this->cache->get($hash, $size, $node);
+                       $file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node);
                        $response->setHeader('Content-Type', $file->getMimeType());
                        $response->setHeader('Content-Disposition', 'inline');
                        $response->setStatus(200);
index 29c45debdefd009a197279ce598f7e4f94ef7f5d..c96259142636ae6002e1fe160d5c668ed907b03c 100644 (file)
@@ -26,15 +26,16 @@ class PhotoCache {
        }
 
        /**
-        * @param string $hash
+        * @param int $addressBookId
+        * @param string $cardUri
         * @param int $size
         * @param Card $card
         *
         * @return ISimpleFile
         * @throws NotFoundException
         */
-       public function get($hash, $size, Card $card) {
-               $folder = $this->getFolder($hash);
+       public function get($addressBookId, $cardUri, $size, Card $card) {
+               $folder = $this->getFolder($addressBookId, $cardUri);
 
                if ($this->isEmpty($folder)) {
                        $this->init($folder, $card);
@@ -132,10 +133,12 @@ class PhotoCache {
 
 
        /**
-        * @param $hash
+        * @param int $addressBookId
+        * @param string $cardUri
         * @return ISimpleFolder
         */
-       private function getFolder($hash) {
+       private function getFolder($addressBookId, $cardUri) {
+               $hash = md5($addressBookId . ' ' . $cardUri);
                try {
                        return $this->appData->getFolder($hash);
                } catch (NotFoundException $e) {
@@ -231,4 +234,13 @@ class PhotoCache {
                }
                return '';
        }
+
+       /**
+        * @param int $addressBookId
+        * @param string $cardUri
+        */
+       public function delete($addressBookId, $cardUri) {
+               $folder = $this->getFolder($addressBookId, $cardUri);
+               $folder->delete();
+       }
 }