summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-07-07 14:54:26 +0200
committerMorris Jobke <hey@morrisjobke.de>2020-07-09 11:43:58 +0200
commitaab646a9d0f67f42fe8eb3398e6b4b726c501585 (patch)
tree1dc26ff116beb28a3b8f8a37136e73610cb33f2c /apps/dav/lib
parent09b9f94c38dda015412cebf2cc8f7c7100001a67 (diff)
downloadnextcloud-server-aab646a9d0f67f42fe8eb3398e6b4b726c501585.tar.gz
nextcloud-server-aab646a9d0f67f42fe8eb3398e6b4b726c501585.zip
Update system addressbook card only when there was a change based on a cached etag
Due to our old and new hook system the card dav backend listens to old and new hooks. This triggers this code multiple times and always causes an update. With this change we cache the etag during a request and only trigger the update if the etag has changed. This does not catches all not needed updates, but it does not need another round trip to the database and still covers most cases where multiple attributes are updated during one single request. Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php14
1 files changed, 14 insertions, 0 deletions
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php
index 8fb48d062d0..9d602025c7a 100644
--- a/apps/dav/lib/CardDAV/CardDavBackend.php
+++ b/apps/dav/lib/CardDAV/CardDavBackend.php
@@ -90,6 +90,8 @@ class CardDavBackend implements BackendInterface, SyncSupport {
/** @var EventDispatcherInterface */
private $dispatcher;
+ private $etagCache = [];
+
/**
* CardDavBackend constructor.
*
@@ -653,6 +655,9 @@ class CardDavBackend implements BackendInterface, SyncSupport {
])
->execute();
+ $etagCacheKey = "$addressBookId#$cardUri";
+ $this->etagCache[$etagCacheKey] = $etag;
+
$this->addChange($addressBookId, $cardUri, 1);
$this->updateProperties($addressBookId, $cardUri, $cardData);
@@ -694,6 +699,13 @@ class CardDavBackend implements BackendInterface, SyncSupport {
$uid = $this->getUID($cardData);
$etag = md5($cardData);
$query = $this->db->getQueryBuilder();
+
+ // check for recently stored etag and stop if it is the same
+ $etagCacheKey = "$addressBookId#$cardUri";
+ if (isset($this->etagCache[$etagCacheKey]) && $this->etagCache[$etagCacheKey] === $etag) {
+ return '"' . $etag . '"';
+ }
+
$query->update($this->dbCardsTable)
->set('carddata', $query->createNamedParameter($cardData, IQueryBuilder::PARAM_LOB))
->set('lastmodified', $query->createNamedParameter(time()))
@@ -704,6 +716,8 @@ class CardDavBackend implements BackendInterface, SyncSupport {
->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
->execute();
+ $this->etagCache[$etagCacheKey] = $etag;
+
$this->addChange($addressBookId, $cardUri, 2);
$this->updateProperties($addressBookId, $cardUri, $cardData);