Fix excessive SQL queries in calendar-sync REPORT

The calendar-sync REPORT fetches the collection as a DAVResource, then
instantiates a DAVResource for each event in the collection.

Unfortunately, ByRow in DAVResource fetches the resource's collection from the
database!

This commit populates each DAVResource's collection field with the
already-fetched collection when performing calendar-sync queries.
This commit is contained in:
Jamie McClymont 2019-01-04 14:03:36 +13:00
parent 7330eaf995
commit c4321dac9f
2 changed files with 11 additions and 3 deletions

View File

@ -148,8 +148,11 @@ class DAVResource
* @param mixed $parameters If null, an empty Resourced is created.
* If it is an object then it is expected to be a record that was
* read elsewhere.
* @param object $prefetched_collection If provided, the internal collection
* field of the resource is populated with the given data, so it does not need
* to be queried again later
*/
function __construct( $parameters = null ) {
function __construct( $parameters = null, DAVResource $prefetched_collection = null ) {
$this->exists = null;
$this->bound_from = null;
$this->dav_name = null;
@ -172,6 +175,11 @@ class DAVResource
$this->_is_external = false;
$this->_is_addressbook = false;
$this->_is_proxy_resource = false;
if ( isset($prefetched_collection) ) {
$this->collection = $prefetched_collection;
}
if ( isset($parameters) && is_object($parameters) ) {
$this->FromRow($parameters);
}

View File

@ -144,7 +144,7 @@ EOSQL;
else if ( $object->sync_status == 201 && $first_status == 404 ) {
// ... Delete ... Create ... is indicated as a create, but don't forget we started with a delete
array_pop($responses);
$dav_resource = new DAVResource($object);
$dav_resource = new DAVResource($object, $collection);
$resultset = $dav_resource->GetPropStat($proplist,$reply);
array_unshift($resultset, new XMLElement( 'href', ConstructURL($object->dav_name)));
$responses[] = new XMLElement( 'response', $resultset );
@ -167,7 +167,7 @@ EOSQL;
$first_status = 404;
}
else {
$dav_resource = new DAVResource($object);
$dav_resource = new DAVResource($object, $collection);
$resultset = $dav_resource->GetPropStat($proplist,$reply);
array_unshift($resultset, new XMLElement( 'href', ConstructURL($object->dav_name)));
$first_status = $object->sync_status;