stream-chat-swift icon indicating copy to clipboard operation
stream-chat-swift copied to clipboard

[WIP] Guard against creating multiple DatabaseContainer instances sharing the DB file

Open laevandus opened this issue 1 year ago โ€ข 3 comments

๐Ÿ”— Issue Links

Hopefully resolves: PBE-5686

๐ŸŽฏ Goal

Do not let multiple DatabaseContainers to modify the DB.

๐Ÿ“ Summary

  • Clear changes in the writableContext when save fails
  • Guard against creating multiple DatabaseContainers which use the common file
  • Remove the canWriteData check because it does not help (serial queue)

๐Ÿ›  Implementation

ChatClient is meant to be a single instance during the app's life-time. If there are multiple instances, the DB state is going to be inconsistent. Therefore, we should guard against this.

๐Ÿงช Manual Testing Notes

N/A

โ˜‘๏ธ Contributor Checklist

  • [x] I have signed the Stream CLA (required)
  • [x] This change should be manually QAed
  • [x] Changelog is updated with client-facing changes
  • [ ] Changelog is updated with new localization keys
  • [x] New code is covered by unit tests
  • [ ] Comparison screenshots added for visual changes
  • [ ] Affected documentation updated (docusaurus, tutorial, CMS)

laevandus avatar Aug 28 '24 11:08 laevandus

SDK Size

title develop branch diff status
StreamChat 6.76 MB 6.76 MB 0 KB ๐ŸŸข
StreamChatUI 4.41 MB 4.41 MB 0 KB ๐ŸŸข

Stream-SDK-Bot avatar Aug 28 '24 11:08 Stream-SDK-Bot

SDK Performance

target metric benchmark branch performance status
MessageList Hitches total duration 10 ms 5.01 ms 49.9% ๐Ÿ”ผ ๐ŸŸข
Duration 2.6 s 2.54 s 2.31% ๐Ÿ”ผ ๐ŸŸข
Hitch time ratio 4 ms per s 1.98 ms per s 50.5% ๐Ÿ”ผ ๐ŸŸข
Frame rate 75 fps 78.04 fps 4.05% ๐Ÿ”ผ ๐ŸŸข
Number of hitches 1 0.4 60.0% ๐Ÿ”ผ ๐ŸŸข
ChannelList Hitches total duration 12.5 ms 17.52 ms -40.16% ๐Ÿ”ฝ ๐Ÿ”ด
Duration 2.6 s 2.54 s 2.31% ๐Ÿ”ผ ๐ŸŸข
Hitch time ratio 5 ms per s 6.89 ms per s -37.8% ๐Ÿ”ฝ ๐Ÿ”ด
Frame rate 72 fps 74.31 fps 3.21% ๐Ÿ”ผ ๐ŸŸข
Number of hitches 1.2 1.8 -50.0% ๐Ÿ”ฝ ๐Ÿ”ด

Stream-SDK-Bot avatar Aug 28 '24 11:08 Stream-SDK-Bot

SDK Size

title develop branch diff status
StreamChat 6.82 MB 6.83 MB +17 KB ๐ŸŸข
StreamChatUI 4.42 MB 4.42 MB 0 KB ๐ŸŸข

Stream-SDK-Bot avatar Aug 28 '24 12:08 Stream-SDK-Bot

I guess we can merge this one - but it's just based on assumptions, right? Btw, some tests are still failing.

Unfortunately can't reproduce the actual crash. This PR aims to make it more clear how multiple ChatClient instances can be used.

laevandus avatar Sep 03 '24 07:09 laevandus