nextcloud / nextcloud/server

CalDavBackend.getCalendarsForUser is executed twice when listing the user's calendar

Open
#49,760 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. Needs triage 30-feedback bug feature: caldav
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

Idea

We know in AppCalendarPlugin.getWrappedCalendars, that we don't care about the calendars from the default backends.
Add a third parameter "skipCalendarProvider" to OC\Calendar\Manager.getCalendarsForPrincipal to skip the default calendar providers.

Reproduce

Set a breakpoint:
https://github.com/nextcloud/server/blob/28ec9c7e80e825aea2537f865e2862aecf25c8f1/apps/dav/lib/CalDAV/CalDavBackend.php#L299

Run:

curl -X PROPFIND "https://admin:admin@server.internal/remote.php/dav/calendars/admin/" \
    -H "Content-Type: application/xml" \
    -H "Cookie: XDEBUG_SESSION=PHPSTORM" \
    -d '<?xml version="1.0"?>
<x0:propfind xmlns:x0="DAV:">
	<x0:prop>
		<x0:current-user-privilege-set/>
		<x0:displayname/>
		<x0:getcontenttype/>
		<x0:getetag/>
		<x0:owner/>
		<x0:resourcetype/>
		<x0:sync-token/>
		<x1:calendar-availability xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
		<x1:calendar-description xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
		<x1:calendar-free-busy-set xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
		<x1:calendar-timezone xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
		<x1:max-attendees-per-instance
				xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
		<x1:max-date-time xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
		<x1:max-instances xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
		<x1:max-resource-size xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
		<x1:min-date-time xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
		<x1:schedule-calendar-transp xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
		<x1:schedule-default-calendar-URL
				xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
		<x1:supported-calendar-component-set
				xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
		<x1:supported-calendar-data xmlns:x1="urn:ietf:params:xml:ns:caldav"/>
		<x3:deleted-at xmlns:x3="http://nextcloud.com/ns"/>
		<x3:owner-displayname xmlns:x3="http://nextcloud.com/ns"/>
		<x3:trash-bin-retention-duration xmlns:x3="http://nextcloud.com/ns"/>
		<x4:calendar-enabled xmlns:x4="http://owncloud.org/ns"/>
		<x4:invite xmlns:x4="http://owncloud.org/ns"/>
		<x5:allowed-sharing-modes xmlns:x5="http://calendarserver.org/ns/"/>
		<x5:getctag xmlns:x5="http://calendarserver.org/ns/"/>
		<x5:publish-url xmlns:x5="http://calendarserver.org/ns/"/>
		<x5:source xmlns:x5="http://calendarserver.org/ns/"/>
		<x5:subscribed-strip-alarms xmlns:x5="http://calendarserver.org/ns/"/>
		<x5:subscribed-strip-attachments
				xmlns:x5="http://calendarserver.org/ns/"/>
		<x5:subscribed-strip-todos xmlns:x5="http://calendarserver.org/ns/"/>
		<x6:calendar-color xmlns:x6="http://apple.com/ns/ical/"/>
		<x6:calendar-order xmlns:x6="http://apple.com/ns/ical/"/>
		<x6:refreshrate xmlns:x6="http://apple.com/ns/ical/"/>
	</x0:prop>
</x0:propfind>'

Stop 1:

CalDavBackend.php:299, OCA\DAV\CalDAV\CalDavBackend->OCA\DAV\CalDAV\{closure:/var/www/html/apps/dav/lib/CalDAV/CalDavBackend.php:298-480}()
TTransactional.php:45, OCA\DAV\CalDAV\CalDavBackend->atomic()
CalDavBackend.php:298, OCA\DAV\CalDAV\CalDavBackend->getCalendarsForUser()
CalendarHome.php:85, OCA\DAV\CalDAV\CalendarHome->getChildren()
Plugin.php:184, OCA\DAV\DAV\Sharing\Plugin->propFind()
WildcardEmitterTrait.php:89, Sabre\DAV\Server->emit()
Server.php:1052, Sabre\DAV\Server->getPropertiesByNode()
Server.php:984, Sabre\DAV\Server->getPropertiesIteratorForPath()
Server.php:1664, Sabre\DAV\Server->writeMultiStatus()
Server.php:1649, Sabre\DAV\Server->generateMultiStatus()
CorePlugin.php:347, Sabre\DAV\CorePlugin->httpPropFind()
WildcardEmitterTrait.php:89, Sabre\DAV\Server->emit()
Server.php:472, Sabre\DAV\Server->invokeMethod()
Server.php:48, OCA\DAV\Connector\Sabre\Server->start()
Server.php:395, OCA\DAV\Server->exec()
remote.php:21, require_once()
remote.php:145, {main}()

Stop 2:

CalDavBackend.php:299, OCA\DAV\CalDAV\CalDavBackend->OCA\DAV\CalDAV\{closure:/var/www/html/apps/dav/lib/CalDAV/CalDavBackend.php:298-480}()
TTransactional.php:45, OCA\DAV\CalDAV\CalDavBackend->atomic()
CalDavBackend.php:298, OCA\DAV\CalDAV\CalDavBackend->getCalendarsForUser()
CalendarProvider.php:28, OCA\DAV\CalDAV\CalendarProvider->getCalendars()
Manager.php:174, OC\Calendar\Manager->OC\Calendar\{closure:/var/www/html/lib/private/Calendar/Manager.php:163-175}()
Manager.php:163, array_map()
Manager.php:163, OC\Calendar\Manager->getCalendarsForPrincipal()
AppCalendarPlugin.php:52, OCA\DAV\CalDAV\AppCalendar\AppCalendarPlugin->getWrappedCalendars()
AppCalendarPlugin.php:34, OCA\DAV\CalDAV\AppCalendar\AppCalendarPlugin->fetchAllForCalendarHome()
CalendarHome.php:118, OCA\DAV\CalDAV\CalendarHome->getChildren()
Plugin.php:184, OCA\DAV\DAV\Sharing\Plugin->propFind()
WildcardEmitterTrait.php:89, Sabre\DAV\Server->emit()
Server.php:1052, Sabre\DAV\Server->getPropertiesByNode()
Server.php:984, Sabre\DAV\Server->getPropertiesIteratorForPath()
Server.php:1664, Sabre\DAV\Server->writeMultiStatus()
Server.php:1649, Sabre\DAV\Server->generateMultiStatus()
CorePlugin.php:347, Sabre\DAV\CorePlugin->httpPropFind()
WildcardEmitterTrait.php:89, Sabre\DAV\Server->emit()
Server.php:472, Sabre\DAV\Server->invokeMethod()
Server.php:48, OCA\DAV\Connector\Sabre\Server->start()
Server.php:395, OCA\DAV\Server->exec()
remote.php:21, require_once()
remote.php:145, {main}()

https://github.com/nextcloud/server/blob/28ec9c7e80e825aea2537f865e2862aecf25c8f1/apps/dav/lib/CalDAV/AppCalendar/AppCalendarPlugin.php#L50-L57

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with apps/dav/lib/CalDAV/AppCalendar/AppCalendarPlugin.php, lib/private/Calendar/Manager.php, and apps/dav/lib/CalDAV/CalendarProvider.php, following the getCalendarsForPrincipal call shown in the stack trace. Reproduce with the provided PROPFIND request and breakpoint in CalDavBackend.php:299; done means the default calendar providers can be skipped for this path so getCalendarsForUser is not executed twice.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.