/** @var EventDispatcherInterface */
private $dispatcher;
+ private $etagCache = [];
+
/**
* CardDavBackend constructor.
*
])
->execute();
+ $etagCacheKey = "$addressBookId#$cardUri";
+ $this->etagCache[$etagCacheKey] = $etag;
+
$this->addChange($addressBookId, $cardUri, 1);
$this->updateProperties($addressBookId, $cardUri, $cardData);
$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()))
->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
->execute();
+ $this->etagCache[$etagCacheKey] = $etag;
+
$this->addChange($addressBookId, $cardUri, 2);
$this->updateProperties($addressBookId, $cardUri, $cardData);
$uri = $this->getUniqueID('card');
// updateProperties is expected twice, once for createCard and once for updateCard
$backend->expects($this->at(0))->method('updateProperties')->with($bookId, $uri, $this->vcardTest0);
- $backend->expects($this->at(1))->method('updateProperties')->with($bookId, $uri, $this->vcardTest0);
+ $backend->expects($this->at(1))->method('updateProperties')->with($bookId, $uri, $this->vcardTest1);
// Expect event
$this->dispatcher->expects($this->at(0))
->with('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $this->callback(function (GenericEvent $e) use ($bookId, $uri) {
return $e->getArgument('addressBookId') === $bookId &&
$e->getArgument('cardUri') === $uri &&
- $e->getArgument('cardData') === $this->vcardTest0;
+ $e->getArgument('cardData') === $this->vcardTest1;
}));
// update the card
- $backend->updateCard($bookId, $uri, $this->vcardTest0);
+ $backend->updateCard($bookId, $uri, $this->vcardTest1);
$card = $backend->getCard($bookId, $uri);
- $this->assertEquals($this->vcardTest0, $card['carddata']);
+ $this->assertEquals($this->vcardTest1, $card['carddata']);
// Expect event
$this->dispatcher->expects($this->at(0))