Skip to content

perf(dav): sync federated calendars with calendar-multiget - #65944

Open
SebastianKrupinski wants to merge 1 commit into
fix/federation-sync-part-3-multigetfrom
fix/federation-sync-part-4-calendar-multiget
Open

SebastianKrupinski wants to merge 1 commit into
fix/federation-sync-part-3-multigetfrom
fix/federation-sync-part-4-calendar-multiget

Conversation

@SebastianKrupinski

@SebastianKrupinski SebastianKrupinski commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Resolves: # No ticket just a improvement like in CardDAV

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@DerDreschner DerDreschner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch is based on an older version of #65942 (0a4754c17b, current is 4524e68cc0), which is why the diff shows #65942's changes again. The difference is only three blank lines in SyncServiceTest.php, and the calendar commit rebases cleanly. My comments on the shared ASyncService/CardDAV code are on #65942 and apply to calendars too (parse failures, missing hrefs, batch size). The inline comments here are about the calendar part only.

Outside the diff:

  • CalDAV/SyncService.php:61 keeps its per-object GET loop and // TODO: use multi-get for download. The class has no callers, so removing it (separately) is probably simpler than converting it.
  • The code-style checks fail: the double blank lines in SyncServiceTest.php go away with the rebase; FederatedCalendarSyncServiceTest.php:298 still needs single quotes (composer cs:fix).
  • Neither commit has an Assisted-by trailer, although the AI box in the description is ticked.

Assisted by ClaudeCode:claude-opus-5-5

$credentials['token'],
$batch,
$reportName,
'{' . Plugin::NS_CALDAV . '}calendar-data',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sabre's CalDAV plugin strips every \r from calendar-data in multiget responses ("Taking out \r to not screw up the xml output"), so objects synced this way are stored with LF line endings, while the GET fallback keeps CRLF. The local ETag and size then differ from the sharer's copy, and local clients get iCalendar without the CRLF that RFC 5545 requires. The test doesn't catch it because the mock encodes \r as 
, which Sabre never sends for calendar-data.

Converting back to CRLF (VObject read + serialize, or \n → \r\n) and making the mock strip \r like Sabre does would fix it.

Comment thread apps/dav/lib/Server.php

// federated calendar shares only need the CalDAV reports, e.g. calendar-multiget for syncing
if ($this->requestIsForSubtree(['remote-calendars'])) {
$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says only the CalDAV reports are needed, but this registers the whole CalDAV plugin for remote-calendars, including validateICalendar for PUTs and MKCALENDAR. When validation repairs an object, Sabre stores it without returning an ETag, and FederatedCalendar::createFile()/updateFile() on the receiver throw on the empty ETag after the sharer already saved the object, so the user gets a 500 for an event that exists. PUTs that used to be accepted can also be rejected with 415 now.

Registering only what the sync needs, or explicitly accepting and testing the new PUT validation, would avoid that.

* @param list<string> $hrefs
* @return \Generator<string, string> Calendar data keyed by href
*
* @throws ClientExceptionInterface If a remote request fails.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requestMultiGet() can also throw Sabre\Xml\LibXMLException (see the parse-failure comment on #65942). That's not a ClientExceptionInterface, so it gets past the catch blocks of FederatedCalendarPeriodicSyncJob and FederatedCalendarSyncJob: the periodic job stops for all remaining calendars, and FederatedCalendarSyncJob skips its setLastSync(1) fallback.

$reportName = '{' . Plugin::NS_CALDAV . '}calendar-multiget';
// Older remotes do not support calendar-multiget for federated calendars and
// would log the rejected report as an error, so ask before sending it
if (!$this->requestReportSupport($credentials['remoteUrl'], $credentials['username'], $credentials['token'], $reportName)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this PROPFIND runs on every sync of every calendar with changes. Caching the result per remote for the duration of a run would save most of them.

Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
@SebastianKrupinski
SebastianKrupinski force-pushed the fix/federation-sync-part-4-calendar-multiget branch from ef428f9 to 698dfeb Compare November 19, 2026 21:29

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews

Projects

Status: 🏗️ In progress

Development

Successfully merging this pull request may close these issues.

2 participants