[Pkg-owncloud-commits] [php-sabredav] 148/163: Better carddav performance. #413.
David Prévot
taffit at moszumanska.debian.org
Tue May 20 18:55:03 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag upstream/2.0.0_beta1
in repository php-sabredav.
commit fddef031b30ffb5d59e36a405298e859661c5ca8
Author: Evert Pot <me at evertpot.com>
Date: Thu May 15 15:20:26 2014 -0400
Better carddav performance. #413.
---
examples/sql/mysql.addressbook.sql | 2 +-
examples/sql/sqlite.addressbooks.sql | 2 +-
lib/CardDAV/Backend/PDO.php | 56 +++++++++++++++++++------
tests/Sabre/CardDAV/Backend/AbstractPDOTest.php | 7 +++-
4 files changed, 50 insertions(+), 17 deletions(-)
diff --git a/examples/sql/mysql.addressbook.sql b/examples/sql/mysql.addressbook.sql
index 5bb6296..4fc33a1 100644
--- a/examples/sql/mysql.addressbook.sql
+++ b/examples/sql/mysql.addressbook.sql
@@ -15,7 +15,7 @@ CREATE TABLE cards (
uri VARCHAR(200),
lastmodified INT(11) UNSIGNED,
etag VARBINARY(32),
- size INT(11) UNSIGNED NOT NULL,
+ size INT(11) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE addressbookchanges (
diff --git a/examples/sql/sqlite.addressbooks.sql b/examples/sql/sqlite.addressbooks.sql
index 43cc993..8a889aa 100644
--- a/examples/sql/sqlite.addressbooks.sql
+++ b/examples/sql/sqlite.addressbooks.sql
@@ -12,7 +12,7 @@ CREATE TABLE cards (
addressbookid integer,
carddata blob,
uri text,
- lastmodified integer
+ lastmodified integer,
etag text,
size integer
);
diff --git a/lib/CardDAV/Backend/PDO.php b/lib/CardDAV/Backend/PDO.php
index 06793ce..3a03077 100644
--- a/lib/CardDAV/Backend/PDO.php
+++ b/lib/CardDAV/Backend/PDO.php
@@ -231,11 +231,15 @@ class PDO extends AbstractBackend implements SyncSupport {
*/
public function getCards($addressbookId) {
- $stmt = $this->pdo->prepare('SELECT id, carddata, uri, lastmodified FROM ' . $this->cardsTableName . ' WHERE addressbookid = ?');
+ $stmt = $this->pdo->prepare('SELECT id, uri, lastmodified, etag, size FROM ' . $this->cardsTableName . ' WHERE addressbookid = ?');
$stmt->execute(array($addressbookId));
- return $stmt->fetchAll(\PDO::FETCH_ASSOC);
-
+ $result = [];
+ while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
+ $row['etag'] = '"' . $row['etag'] . '"';
+ $result[] = $row;
+ }
+ return $result;
}
@@ -253,12 +257,15 @@ class PDO extends AbstractBackend implements SyncSupport {
*/
public function getCard($addressBookId, $cardUri) {
- $stmt = $this->pdo->prepare('SELECT id, carddata, uri, lastmodified FROM ' . $this->cardsTableName . ' WHERE addressbookid = ? AND uri = ? LIMIT 1');
+ $stmt = $this->pdo->prepare('SELECT id, carddata, uri, lastmodified, etag, size FROM ' . $this->cardsTableName . ' WHERE addressbookid = ? AND uri = ? LIMIT 1');
$stmt->execute(array($addressBookId, $cardUri));
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
- return $result?$result:false;
+ if (!$result) return false;
+
+ $result['etag'] = '"' . $result['etag'] . '"';
+ return $result;
}
@@ -280,14 +287,19 @@ class PDO extends AbstractBackend implements SyncSupport {
return $this->getCard($addressBookId, $uri);
}, $uris);
- $query = 'SELECT id, carddata, uri, lastmodified FROM ' . $this->cardsTableName . ' WHERE addressbookid = ? AND uri = IN (';
+ $query = 'SELECT id, uri, lastmodified, etag, size FROM ' . $this->cardsTableName . ' WHERE addressbookid = ? AND uri = IN (';
// Inserting a whole bunch of question marks
$query.=implode(',', array_fill(0, count($uris), '?'));
$query.=')';
$stmt = $this->pdo->prepare($query);
$stmt->execute(array_merge([$addressBookId], $uris));
- return $stmt->fetchAll(\PDO::FETCH_ASSOC);
+ $result = [];
+ while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
+ $row['etag'] = '"' . $row['etag'] . '"';
+ $result[] = $row;
+ }
+ return $result;
}
@@ -318,13 +330,22 @@ class PDO extends AbstractBackend implements SyncSupport {
*/
public function createCard($addressBookId, $cardUri, $cardData) {
- $stmt = $this->pdo->prepare('INSERT INTO ' . $this->cardsTableName . ' (carddata, uri, lastmodified, addressbookid) VALUES (?, ?, ?, ?)');
+ $stmt = $this->pdo->prepare('INSERT INTO ' . $this->cardsTableName . ' (carddata, uri, lastmodified, addressbookid, size, etag) VALUES (?, ?, ?, ?, ?, ?)');
- $result = $stmt->execute(array($cardData, $cardUri, time(), $addressBookId));
+ $etag = md5($cardData);
+
+ $result = $stmt->execute([
+ $cardData,
+ $cardUri,
+ time(),
+ $addressBookId,
+ strlen($cardData),
+ $etag,
+ ]);
$this->addChange($addressBookId, $cardUri, 1);
- return '"' . md5($cardData) . '"';
+ return '"' . $etag . '"';
}
@@ -355,12 +376,21 @@ class PDO extends AbstractBackend implements SyncSupport {
*/
public function updateCard($addressBookId, $cardUri, $cardData) {
- $stmt = $this->pdo->prepare('UPDATE ' . $this->cardsTableName . ' SET carddata = ?, lastmodified = ? WHERE uri = ? AND addressbookid =?');
- $stmt->execute(array($cardData, time(), $cardUri, $addressBookId));
+ $stmt = $this->pdo->prepare('UPDATE ' . $this->cardsTableName . ' SET carddata = ?, lastmodified = ?, size = ?, etag = ? WHERE uri = ? AND addressbookid =?');
+
+ $etag = md5($cardData);
+ $stmt->execute([
+ $cardData,
+ time(),
+ strlen($cardData),
+ $etag,
+ $cardUri,
+ $addressBookId
+ ]);
$this->addChange($addressBookId, $cardUri, 2);
- return '"' . md5($cardData) . '"';
+ return '"' . $etag . '"';
}
diff --git a/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php b/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php
index afd9e04..ffa086e 100644
--- a/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php
+++ b/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php
@@ -23,7 +23,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$pdo = $this->getPDO();
$this->backend = new PDO($pdo);
$pdo->exec('INSERT INTO addressbooks (principaluri, displayname, uri, description, synctoken) VALUES ("principals/user1", "book1", "book1", "addressbook 1", 1)');
- $pdo->exec('INSERT INTO cards (addressbookid, carddata, uri, lastmodified) VALUES (1, "card1", "card1", 0)');
+ $pdo->exec('INSERT INTO cards (addressbookid, carddata, uri, lastmodified, etag, size) VALUES (1, "card1", "card1", 0, "' . md5('card1') . '", 5)');
}
@@ -202,8 +202,9 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
array(
'id' => 1,
'uri' => 'card1',
- 'carddata' => 'card1',
'lastmodified' => 0,
+ 'etag' => '"' . md5('card1') . '"',
+ 'size' => 5
)
);
@@ -220,6 +221,8 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'uri' => 'card1',
'carddata' => 'card1',
'lastmodified' => 0,
+ 'etag' => '"' . md5('card1') . '"',
+ 'size' => 5
);
$this->assertEquals($expected, $result);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list