flamelink / flamelink-js-sdk

🦊 Official Flamelink JavaScript SDK for both the Firebase Realtime database and Cloud Firestore
https://flamelink.github.io/flamelink-js-sdk
MIT License
43 stars 5 forks source link

Web UI crashes when large collection updated via API #176

Open petermenocal opened 2 years ago

petermenocal commented 2 years ago

When using the JS SDK to update a large number of collection items, the web UI at app.flamelink.io will completely crash and freeze. Experience has been repeatable in both Safari and Firefox on MacOS.

I've attached a video of the behavior. In this clip, you'll see the interface responsive, the API request sent, and finally the interface frozen.

Steps to reproduce:

This is presumably happening because the entire list of items is loaded into that paginated table and listened to with the realtime subscriber. Is there a way we can disable this somehow to increase performance for large collections that get updated?

Video of issue: https://user-images.githubusercontent.com/22479535/126672010-e4775b96-57b8-46ac-b054-e5f22d2da26b.mov

gitdubz commented 2 years ago

Hi,

For large collection updates does the same happen when doing updates using batch updates? https://firebase.google.com/docs/firestore/manage-data/transactions#web-v8_2

petermenocal commented 2 years ago

I'm using the real-time database which I don't believe has batched updates like Firestore.

gitdubz commented 2 years ago

Ah okay. So on our end, how we handle large collection updates for RTDB is to only update the app state (referring to react & redux) when the last item in the list of updates is done. This way the UI does not do 800 re-renders, it only does 1.

This is however not controllable via the SDK/API since the app will respond to each update as if it is not a bulk operation.

The only way this can potentially be achieved is if a bulk operation is provided on the SDK which would take all the updates and apply it as 1 single update to the RTDB object.

You could do this yourself using the raw Firebase functionality. https://firebase.google.com/docs/database/web/read-and-write#update_specific_fields

firebaseApp
  .database()
  .ref('flamelink/environments/production/content/schemaKey/en-US')
  .update({ 
    '1234567890': { 
      __meta__: { 
        lastModifiedBy: 'yourUserId', 
        lastModifiedData: new Date().toISOString() 
      }, 
      ... 
    },
    '0987654321': { ... }
  })

NOTE: You would need to handle the lastModifiedBy and lastModifiedDate values