nextcloud / nextcloud/server

[Bug]: Optimize Deletion of Objects for Calendar Subscriptions

Open
#51,120 7 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

1. to develop 30-feedback 32-feedback bug feature: caldav
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

Description:

The RefreshWebcalService is responsible for updating calendar subscriptions. Since Nextcloud 30, the updated source is diffed against the local state, and only changes are written back.

Recently, we investigated a system with an unusually large oc_calendarobjects table and recurring deadlocks when removing calendar objects that no longer exist in the source.

Findings:

It turned out that the user had subscribed to a calendar from a Redmine instance. This subscription changed the UID on every request and contained a rather large set of events.

As a result, every time the subscription was refreshed, around 15,000 objects needed to be removed. This process affects the following tables:

  • oc_calendarobjects_props
  • oc_calendarobjects
  • oc_calendarchanges (twice)

Currently, these deletions are handled within a single transaction, significantly increasing the risk of deadlocks.

Suggested Improvement:

To reduce the likelihood of deadlocks, we should consider optimizing how deletions are handled—potentially by breaking them into smaller transactions or batching the deletions more efficiently.

Additional information

Script to simulate such a calendar feed: https://github.com/kesselb/weird-calendars/blob/main/calendar_subscription_with_unstable_uid.php

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 RefreshWebcalService and trace how deletions affect oc_calendarobjects_props, oc_calendarobjects, and oc_calendarchanges. Use the linked calendar_subscription_with_unstable_uid.php script to reproduce the large unstable-UID feed, then verify that refreshing it removes obsolete objects with lower deadlock risk while preserving the local calendar state.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.