@@ -217,6 +217,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
217217 private IConfig $ config ;
218218 private bool $ legacyEndpoint ;
219219 private string $ dbObjectPropertiesTable = 'calendarobjects_props ' ;
220+ private array $ cachedObjects = [];
220221
221222 public function __construct (IDBConnection $ db ,
222223 Principal $ principalBackend ,
@@ -1104,6 +1105,10 @@ public function getDeletedCalendarObjectsByPrincipal(string $principalUri): arra
11041105 * @return array|null
11051106 */
11061107 public function getCalendarObject ($ calendarId , $ objectUri , int $ calendarType = self ::CALENDAR_TYPE_CALENDAR ) {
1108+ $ key = $ calendarId . ':: ' . $ objectUri . ':: ' . $ calendarType ;
1109+ if (isset ($ this ->cachedObjects [$ key ])) {
1110+ return $ this ->cachedObjects [$ key ];
1111+ }
11071112 $ query = $ this ->db ->getQueryBuilder ();
11081113 $ query ->select (['id ' , 'uri ' , 'lastmodified ' , 'etag ' , 'calendarid ' , 'size ' , 'calendardata ' , 'componenttype ' , 'classification ' , 'deleted_at ' ])
11091114 ->from ('calendarobjects ' )
@@ -1118,6 +1123,12 @@ public function getCalendarObject($calendarId, $objectUri, int $calendarType = s
11181123 return null ;
11191124 }
11201125
1126+ $ object = $ this ->rowToCalendarObject ($ row );
1127+ $ this ->cachedObjects [$ key ] = $ object ;
1128+ return $ object ;
1129+ }
1130+
1131+ private function rowToCalendarObject (array $ row ): array {
11211132 return [
11221133 'id ' => $ row ['id ' ],
11231134 'uri ' => $ row ['uri ' ],
@@ -1204,6 +1215,7 @@ public function getMultipleCalendarObjects($calendarId, array $uris, $calendarTy
12041215 * @return string
12051216 */
12061217 public function createCalendarObject ($ calendarId , $ objectUri , $ calendarData , $ calendarType = self ::CALENDAR_TYPE_CALENDAR ) {
1218+ $ this ->cachedObjects = [];
12071219 $ extraData = $ this ->getDenormalizedData ($ calendarData );
12081220
12091221 // Try to detect duplicates
@@ -1296,6 +1308,7 @@ public function createCalendarObject($calendarId, $objectUri, $calendarData, $ca
12961308 * @return string
12971309 */
12981310 public function updateCalendarObject ($ calendarId , $ objectUri , $ calendarData , $ calendarType = self ::CALENDAR_TYPE_CALENDAR ) {
1311+ $ this ->cachedObjects = [];
12991312 $ extraData = $ this ->getDenormalizedData ($ calendarData );
13001313 $ query = $ this ->db ->getQueryBuilder ();
13011314 $ query ->update ('calendarobjects ' )
@@ -1346,6 +1359,7 @@ public function updateCalendarObject($calendarId, $objectUri, $calendarData, $ca
13461359 * @throws Exception
13471360 */
13481361 public function moveCalendarObject (int $ sourceCalendarId , int $ targetCalendarId , int $ objectId , string $ oldPrincipalUri , string $ newPrincipalUri , int $ calendarType = self ::CALENDAR_TYPE_CALENDAR ): bool {
1362+ $ this ->cachedObjects = [];
13491363 $ object = $ this ->getCalendarObjectById ($ oldPrincipalUri , $ objectId );
13501364 if (empty ($ object )) {
13511365 return false ;
@@ -1391,6 +1405,7 @@ public function moveCalendarObject(int $sourceCalendarId, int $targetCalendarId,
13911405 * @param int $classification
13921406 */
13931407 public function setClassification ($ calendarObjectId , $ classification ) {
1408+ $ this ->cachedObjects = [];
13941409 if (!in_array ($ classification , [
13951410 self ::CLASSIFICATION_PUBLIC , self ::CLASSIFICATION_PRIVATE , self ::CLASSIFICATION_CONFIDENTIAL
13961411 ])) {
@@ -1415,6 +1430,7 @@ public function setClassification($calendarObjectId, $classification) {
14151430 * @return void
14161431 */
14171432 public function deleteCalendarObject ($ calendarId , $ objectUri , $ calendarType = self ::CALENDAR_TYPE_CALENDAR , bool $ forceDeletePermanently = false ) {
1433+ $ this ->cachedObjects = [];
14181434 $ data = $ this ->getCalendarObject ($ calendarId , $ objectUri , $ calendarType );
14191435
14201436 if ($ data === null ) {
@@ -1494,6 +1510,7 @@ public function deleteCalendarObject($calendarId, $objectUri, $calendarType = se
14941510 * @throws Forbidden
14951511 */
14961512 public function restoreCalendarObject (array $ objectData ): void {
1513+ $ this ->cachedObjects = [];
14971514 $ id = (int ) $ objectData ['id ' ];
14981515 $ restoreUri = str_replace ("-deleted.ics " , ".ics " , $ objectData ['uri ' ]);
14991516 $ targetObject = $ this ->getCalendarObject (
@@ -1619,12 +1636,8 @@ public function calendarQuery($calendarId, array $filters, $calendarType = self:
16191636 }
16201637 }
16211638 }
1622- $ columns = ['uri ' ];
1623- if ($ requirePostFilter ) {
1624- $ columns = ['uri ' , 'calendardata ' ];
1625- }
16261639 $ query = $ this ->db ->getQueryBuilder ();
1627- $ query ->select ($ columns )
1640+ $ query ->select ([ ' id ' , ' uri ' , ' lastmodified ' , ' etag ' , ' calendarid ' , ' size ' , ' calendardata ' , ' componenttype ' , ' classification ' , ' deleted_at ' ] )
16281641 ->from ('calendarobjects ' )
16291642 ->where ($ query ->expr ()->eq ('calendarid ' , $ query ->createNamedParameter ($ calendarId )))
16301643 ->andWhere ($ query ->expr ()->eq ('calendartype ' , $ query ->createNamedParameter ($ calendarType )))
@@ -1645,6 +1658,11 @@ public function calendarQuery($calendarId, array $filters, $calendarType = self:
16451658
16461659 $ result = [];
16471660 while ($ row = $ stmt ->fetch ()) {
1661+ // if we leave it as a blob we can't read it both from the post filter and the rowToCalendarObject
1662+ if (isset ($ row ['calendardata ' ])) {
1663+ $ row ['calendardata ' ] = $ this ->readBlob ($ row ['calendardata ' ]);
1664+ }
1665+
16481666 if ($ requirePostFilter ) {
16491667 // validateFilterForObject will parse the calendar data
16501668 // catch parsing errors
@@ -1669,6 +1687,8 @@ public function calendarQuery($calendarId, array $filters, $calendarType = self:
16691687 }
16701688 }
16711689 $ result [] = $ row ['uri ' ];
1690+ $ key = $ calendarId . ':: ' . $ row ['uri ' ] . ':: ' . $ calendarType ;
1691+ $ this ->cachedObjects [$ key ] = $ this ->rowToCalendarObject ($ row );
16721692 }
16731693
16741694 return $ result ;
@@ -2619,6 +2639,7 @@ public function getSchedulingObjects($principalUri) {
26192639 * @return void
26202640 */
26212641 public function deleteSchedulingObject ($ principalUri , $ objectUri ) {
2642+ $ this ->cachedObjects = [];
26222643 $ query = $ this ->db ->getQueryBuilder ();
26232644 $ query ->delete ('schedulingobjects ' )
26242645 ->where ($ query ->expr ()->eq ('principaluri ' , $ query ->createNamedParameter ($ principalUri )))
@@ -2635,6 +2656,7 @@ public function deleteSchedulingObject($principalUri, $objectUri) {
26352656 * @return void
26362657 */
26372658 public function createSchedulingObject ($ principalUri , $ objectUri , $ objectData ) {
2659+ $ this ->cachedObjects = [];
26382660 $ query = $ this ->db ->getQueryBuilder ();
26392661 $ query ->insert ('schedulingobjects ' )
26402662 ->values ([
@@ -2658,6 +2680,7 @@ public function createSchedulingObject($principalUri, $objectUri, $objectData) {
26582680 * @return void
26592681 */
26602682 protected function addChange ($ calendarId , $ objectUri , $ operation , $ calendarType = self ::CALENDAR_TYPE_CALENDAR ) {
2683+ $ this ->cachedObjects = [];
26612684 $ table = $ calendarType === self ::CALENDAR_TYPE_CALENDAR ? 'calendars ' : 'calendarsubscriptions ' ;
26622685
26632686 $ query = $ this ->db ->getQueryBuilder ();
@@ -2824,7 +2847,7 @@ public function getShares(int $resourceId): array {
28242847 return $ this ->calendarSharingBackend ->getShares ($ resourceId );
28252848 }
28262849
2827- public function preloadShares (array $ resourceIds ) {
2850+ public function preloadShares (array $ resourceIds ): void {
28282851 $ this ->calendarSharingBackend ->preloadShares ($ resourceIds );
28292852 }
28302853
@@ -2897,6 +2920,7 @@ public function applyShareAcl(int $resourceId, array $acl): array {
28972920 * @param int $calendarType
28982921 */
28992922 public function updateProperties ($ calendarId , $ objectUri , $ calendarData , $ calendarType = self ::CALENDAR_TYPE_CALENDAR ) {
2923+ $ this ->cachedObjects = [];
29002924 $ objectId = $ this ->getCalendarObjectId ($ calendarId , $ objectUri , $ calendarType );
29012925
29022926 try {
@@ -3055,6 +3079,7 @@ protected function readCalendarData($objectData) {
30553079 * @param int $objectId
30563080 */
30573081 protected function purgeProperties ($ calendarId , $ objectId ) {
3082+ $ this ->cachedObjects = [];
30583083 $ query = $ this ->db ->getQueryBuilder ();
30593084 $ query ->delete ($ this ->dbObjectPropertiesTable )
30603085 ->where ($ query ->expr ()->eq ('objectid ' , $ query ->createNamedParameter ($ objectId )))
0 commit comments