private IConfig $config;
private bool $legacyEndpoint;
private string $dbObjectPropertiesTable = 'calendarobjects_props';
+ private array $cachedObjects = [];
public function __construct(IDBConnection $db,
Principal $principalBackend,
* @return array|null
*/
public function getCalendarObject($calendarId, $objectUri, int $calendarType = self::CALENDAR_TYPE_CALENDAR) {
+ $key = $calendarId . '::' . $objectUri . '::' . $calendarType;
+ if (isset($this->cachedObjects[$key])) {
+ return $this->cachedObjects[$key];
+ }
$query = $this->db->getQueryBuilder();
$query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification', 'deleted_at'])
->from('calendarobjects')
return null;
}
+ $object = $this->rowToCalendarObject($row);
+ $this->cachedObjects[$key] = $object;
+ return $object;
+ }
+
+ private function rowToCalendarObject(array $row): array {
return [
'id' => $row['id'],
'uri' => $row['uri'],
* @return string
*/
public function createCalendarObject($calendarId, $objectUri, $calendarData, $calendarType = self::CALENDAR_TYPE_CALENDAR) {
+ $this->cachedObjects = [];
$extraData = $this->getDenormalizedData($calendarData);
return $this->atomic(function () use ($calendarId, $objectUri, $calendarData, $extraData, $calendarType) {
* @return string
*/
public function updateCalendarObject($calendarId, $objectUri, $calendarData, $calendarType = self::CALENDAR_TYPE_CALENDAR) {
+ $this->cachedObjects = [];
$extraData = $this->getDenormalizedData($calendarData);
return $this->atomic(function () use ($calendarId, $objectUri, $calendarData, $extraData, $calendarType) {
* @throws Exception
*/
public function moveCalendarObject(int $sourceCalendarId, int $targetCalendarId, int $objectId, string $oldPrincipalUri, string $newPrincipalUri, int $calendarType = self::CALENDAR_TYPE_CALENDAR): bool {
+ $this->cachedObjects = [];
return $this->atomic(function () use ($sourceCalendarId, $targetCalendarId, $objectId, $oldPrincipalUri, $newPrincipalUri, $calendarType) {
$object = $this->getCalendarObjectById($oldPrincipalUri, $objectId);
if (empty($object)) {
* @param int $classification
*/
public function setClassification($calendarObjectId, $classification) {
+ $this->cachedObjects = [];
if (!in_array($classification, [
self::CLASSIFICATION_PUBLIC, self::CLASSIFICATION_PRIVATE, self::CLASSIFICATION_CONFIDENTIAL
])) {
* @return void
*/
public function deleteCalendarObject($calendarId, $objectUri, $calendarType = self::CALENDAR_TYPE_CALENDAR, bool $forceDeletePermanently = false) {
+ $this->cachedObjects = [];
$this->atomic(function () use ($calendarId, $objectUri, $calendarType, $forceDeletePermanently) {
$data = $this->getCalendarObject($calendarId, $objectUri, $calendarType);
* @throws Forbidden
*/
public function restoreCalendarObject(array $objectData): void {
+ $this->cachedObjects = [];
$this->atomic(function () use ($objectData) {
$id = (int) $objectData['id'];
$restoreUri = str_replace("-deleted.ics", ".ics", $objectData['uri']);
}
}
}
- $columns = ['uri'];
- if ($requirePostFilter) {
- $columns = ['uri', 'calendardata'];
- }
$query = $this->db->getQueryBuilder();
- $query->select($columns)
+ $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification', 'deleted_at'])
->from('calendarobjects')
->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId)))
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType)))
$result = [];
while ($row = $stmt->fetch()) {
+ // if we leave it as a blob we can't read it both from the post filter and the rowToCalendarObject
+ if (isset($row['calendardata'])) {
+ $row['calendardata'] = $this->readBlob($row['calendardata']);
+ }
+
if ($requirePostFilter) {
// validateFilterForObject will parse the calendar data
// catch parsing errors
}
}
$result[] = $row['uri'];
+ $key = $calendarId . '::' . $row['uri'] . '::' . $calendarType;
+ $this->cachedObjects[$key] = $this->rowToCalendarObject($row);
}
return $result;
* @return void
*/
public function deleteSchedulingObject($principalUri, $objectUri) {
+ $this->cachedObjects = [];
$query = $this->db->getQueryBuilder();
$query->delete('schedulingobjects')
->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)))
* @return void
*/
public function createSchedulingObject($principalUri, $objectUri, $objectData) {
+ $this->cachedObjects = [];
$query = $this->db->getQueryBuilder();
$query->insert('schedulingobjects')
->values([
* @return void
*/
protected function addChange(int $calendarId, string $objectUri, int $operation, int $calendarType = self::CALENDAR_TYPE_CALENDAR): void {
+ $this->cachedObjects = [];
$table = $calendarType === self::CALENDAR_TYPE_CALENDAR ? 'calendars': 'calendarsubscriptions';
$this->atomic(function () use ($calendarId, $objectUri, $operation, $calendarType, $table) {
* @param int $calendarType
*/
public function updateProperties($calendarId, $objectUri, $calendarData, $calendarType = self::CALENDAR_TYPE_CALENDAR) {
+ $this->cachedObjects = [];
$this->atomic(function () use ($calendarId, $objectUri, $calendarData, $calendarType) {
$objectId = $this->getCalendarObjectId($calendarId, $objectUri, $calendarType);
* @param int $objectId
*/
protected function purgeProperties($calendarId, $objectId) {
+ $this->cachedObjects = [];
$query = $this->db->getQueryBuilder();
$query->delete($this->dbObjectPropertiesTable)
->where($query->expr()->eq('objectid', $query->createNamedParameter($objectId)))