mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-18 07:52:21 +01:00
Contacts: Enable Caching contact list if not changed.
This commit is contained in:
parent
4a589de7bc
commit
edd356a252
@ -29,7 +29,12 @@ if(is_null($aid)) {
|
||||
$active_addressbooks = array(OCA\Contacts\Addressbook::find($aid));
|
||||
}
|
||||
|
||||
|
||||
$lastModified = OCA\Contacts\App::lastModified();
|
||||
if(!is_null($lastModified)) {
|
||||
OCP\Response::enableCaching();
|
||||
OCP\Response::setLastModifiedHeader($lastModified);
|
||||
OCP\Response::setETagHeader(md5($lastModified->format('U')));
|
||||
}
|
||||
session_write_close();
|
||||
|
||||
// create the addressbook associate array
|
||||
|
17
lib/app.php
17
lib/app.php
@ -278,7 +278,7 @@ class App {
|
||||
|
||||
/**
|
||||
* @brief Get the last modification time.
|
||||
* @param OC_VObject|Sabre\VObject\Component|integer $contact
|
||||
* @param OC_VObject|Sabre\VObject\Component|integer|null $contact
|
||||
* @returns DateTime | null
|
||||
*/
|
||||
public static function lastModified($contact) {
|
||||
@ -289,6 +289,21 @@ class App {
|
||||
return isset($contact->REV)
|
||||
? \DateTime::createFromFormat(\DateTime::W3C, $contact->REV)
|
||||
: null;
|
||||
} elseif(is_null($contact)) {
|
||||
// FIXME: This doesn't take shared address books into account.
|
||||
$sql = 'SELECT MAX(`lastmodified`) FROM `oc_contacts_cards`, `oc_contacts_addressbooks` ' .
|
||||
'WHERE `oc_contacts_cards`.`addressbookid` = `oc_contacts_addressbooks`.`id` AND ' .
|
||||
'`oc_contacts_addressbooks`.`userid` = ?';
|
||||
$stmt = \OCP\DB::prepare($sql);
|
||||
$result = $stmt->execute(array(\OCP\USER::getUser()));
|
||||
if (\OC_DB::isError($result)) {
|
||||
\OC_Log::write('contacts', __METHOD__. 'DB error: ' . \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
|
||||
return null;
|
||||
}
|
||||
$lastModified = $result->fetchOne();
|
||||
if(!is_null($lastModified)) {
|
||||
return new \DateTime('@' . $lastModified);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user