A calendar was deleted, but it left behind orphan entries in the database - how do I clean that up?

Hi all,

I have some calendars that have been deleted from Nextcloud, but they still have left over related items.

For example:

mayfirst=> SELECT DISTINCT calendarid FROM oc_calendarobjects WHERE calendarid NOT IN (SELECT id FROM oc_calendars);
 calendarid 
------------
        438
        443
        444
        446
        447
        451
        455
        463
(8 rows)

mayfirst=>

Is there any utility to cleanly delete left over calendar objects from the database?

I can see that there is a lot of deleting that goes on under the hood. I’m not sure I’m confident I can do it all properly. Especially since it seems there are some listeners in the code that would be hard to fully track down.

Any tips would be appreciated.

Hi,

Be careful when modifying oc_calendarobjects directly.

The calendarid in oc_calendarobjects belong either to oc_calendars or oc_calendarsubscriptions.

So your above query should include calendartype=0 to only check for elements belonging to calendars from oc_calendars.

There’s a background job “CleanupOrphanedChildrenJob” to clean up orphaned entries.

2 Likes

Thank you @kesselb - this is really helpful.

I see a function called removeOrphanChildren.

It seems to be exactly what I am looking for. Is that what you are referring to? Under what conditions does it run?

jamie

I think the background job is scheduled automatically after updating nextcloud or manually via occ maintenance:repair. Afaik it’s usually not necessary to run it frequently.