Import huge iCloud calendars into nextCloud (without explosions)

Three weeks ago I received an URL of a really big iCloud shared calendar.

(Having said I’ve nothing against an iCloud shared calendar. If I can use free software to access it, that’s fine.)

So I tried importing that URL into my nextCloud instance.

So I caused very long time of CPU consumption and nextCloud explosions.

Allowed memory size of 1048576000 bytes exhausted

Long story short. iCloud takes six (6!) seconds to generate that huge document; nextCloud invests too much resources in parsing that wall of data.

Now. You can surely increase your limits… but it’s not a good idea to allow a spike of GBs of RAM and seconds and seconds of userspace CPU consumption just to see 50 fresh events, together with 500k legacy events. asd

Also because if you need to stay in sync you have to repeat this operation every some minute.

In order not to blow up my server and not slow down my computers and my LineageOS phone and to save electricity from Apple (which I think does a lot of calculations as well… asd) I wrote a script that orders my server to:

  1. download that shared calendar from iCloud (this takes at least 6 seconds asd)
  2. parse the content
  3. filter by creation date or last modification (sometimes the creation date is missing – asd)
  4. discard the appointments older than 6 months
  5. reconsolidate the remaining events
  6. save the result
  7. expose this last clean calendar to my nextCloud via HTTP

A daemon goes through this preparation process every 20 minutes. At the end I obtain a lightweight and fast resource to be scan by nextCloud whenever it wants, even every second.

Long story short:

  • Apple is happy
  • I’m happy
  • my nextCloud is happy

If you need that script: