jkomoros / card-web

The web app behind thecompendium.cards
Apache License 2.0
53 stars 8 forks source link

Get rid of cloud functions-based updateInboundLinks #585

Closed jkomoros closed 2 years ago

jkomoros commented 2 years ago

We use cloud functions on card writes, mainly to fix up and update inboundLinks.

The reason it's a cloud function is to verify that even badly behaved clients can't mess up the two-way references (outbound and inbound), but also because technically it's possible for an editor of a card to add or remove a reference to a card they aren't able to see (let alone edit). But the machinery is a total pain in the butt--there's a lot of awkward code sharing going on for that function, and the fact that each edited card has its handlers one run at a time, roughly once per second, means that after a multi-edit, we'll get a stream of disruptive card-updates, one at a time, one per second, and each time ruining all of the expensive caches clientside and leading to a whole pipeline recreation.

The last odd bit of #581 is how to do an elaborate dance to work around this behavior. But honestly, it's probably just simpler to rip out the cloud function in the first place and do it all clientside anyway, we already do most of the calculation of inbound links updates in modifyCardWithBatch. If we did this, then we'd be able to get rid of the whole card overlay system and instead just have the immediate firestore onSnapshot handle everything... and in updateCards, just ignore timestamps. We'd also be able to rip out the odd server-side maintenanceMode that effectively just turns off inbound links.

The one downside is there's an edge case noted above about adding or removing references to cards the current user can't see... but that's very very rare, and only is affected when one of those is added or removed, not when one simply persists across an edit. For those, we can just disallow removing references to cards we can't see (it's already impossble int the UI to add a reference to a card you can't see.)

jkomoros commented 2 years ago
jkomoros commented 2 years ago

This issue is now finished