diff options
author | Anna Larch <anna@nextcloud.com> | 2024-05-08 20:38:51 +0200 |
---|---|---|
committer | Anna Larch <anna@nextcloud.com> | 2024-05-31 13:14:01 +0200 |
commit | ad78f7e48e7f03fc6c3f47a8972d122cde275d97 (patch) | |
tree | 220b6a13bbe7be61b60f4bda5bfe118bf3bc28ce /apps/dav/lib/CalDAV | |
parent | 4a6ac1f1aab769089b1b48a45bbb15bd1fb847e1 (diff) | |
download | nextcloud-server-ad78f7e48e7f03fc6c3f47a8972d122cde275d97.tar.gz nextcloud-server-ad78f7e48e7f03fc6c3f47a8972d122cde275d97.zip |
fix(caldav): automatically delete outdated scheduling objects
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'apps/dav/lib/CalDAV')
-rw-r--r-- | apps/dav/lib/CalDAV/CalDavBackend.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index d17c8a350fc..cc6c4344c3c 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -2776,6 +2776,44 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } /** + * Deletes all scheduling objects last modified before $modifiedBefore from the inbox collection. + * + * @param int $modifiedBefore + * @param int $limit + * @return void + */ + public function deleteOutdatedSchedulingObjects(int $modifiedBefore, int $limit): void { + $query = $this->db->getQueryBuilder(); + $query->select('id') + ->from('schedulingobjects') + ->where($query->expr()->lt('lastmodified', $query->createNamedParameter($modifiedBefore))) + ->setMaxResults($limit); + $result = $query->executeQuery(); + $count = $result->rowCount(); + if($count === 0) { + return; + } + $ids = array_map(static function (array $id) { + return (int)$id[0]; + }, $result->fetchAll(\PDO::FETCH_NUM)); + $result->closeCursor(); + + $numDeleted = 0; + $deleteQuery = $this->db->getQueryBuilder(); + $deleteQuery->delete('schedulingobjects') + ->where($deleteQuery->expr()->in('id', $deleteQuery->createParameter('ids'), IQueryBuilder::PARAM_INT_ARRAY)); + foreach(array_chunk($ids, 1000) as $chunk) { + $deleteQuery->setParameter('ids', $chunk, IQueryBuilder::PARAM_INT_ARRAY); + $numDeleted += $deleteQuery->executeStatement(); + } + + if($numDeleted === $limit) { + $this->logger->info("Deleted $limit scheduling objects, continuing with next batch"); + $this->deleteOutdatedSchedulingObjects($modifiedBefore, $limit); + } + } + + /** * Creates a new scheduling object. This should land in a users' inbox. * * @param string $principalUri |