Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read data using a background context in the DataStore #3541

Merged
merged 1 commit into from
Dec 23, 2024

Conversation

laevandus
Copy link
Contributor

@laevandus laevandus commented Dec 23, 2024

🔗 Issue Links

Resolves IOS-626

🎯 Goal

DataStore is public and therefore we should not have the main thread requirement which can be misused easily

📝 Summary

  • Force all thread data reads to the background context's queue

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change should be manually QAed
  • Changelog is updated with client-facing changes
  • Changelog is updated with new localization keys
  • New code is covered by unit tests
  • Documentation has been updated in the docs-content repo

@laevandus laevandus added 🐞 Bug An issue or PR related to a bug 🌐 SDK: StreamChat (LLC) Tasks related to the StreamChat LLC SDK labels Dec 23, 2024
@laevandus laevandus requested a review from a team as a code owner December 23, 2024 08:31
Comment on lines +286 to +302
func readAndWait<T>(_ actions: (DatabaseSession) throws -> T) throws -> T {
let context = viewContext
var result: T?
var readError: Error?
context.performAndWait {
do {
result = try actions(context)
} catch {
readError = error
}
}
if let result {
return result
} else {
throw readError ?? ClientError.Unknown()
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing performAndWait is iOS 15 or later, therefore this is not so pretty at the moment.

@laevandus laevandus force-pushed the fix/data-store-access branch from 1810be2 to 56771e1 Compare December 23, 2024 08:35
@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Dec 23, 2024

SDK Size

title develop branch diff status
StreamChat 7.03 MB 7.03 MB +1 KB 🟢
StreamChatUI 4.77 MB 4.77 MB 0 KB 🟢

@Stream-SDK-Bot
Copy link
Collaborator

SDK Performance

target metric benchmark branch performance status
MessageList Hitches total duration 10 ms 10.01 ms -0.1% 🔽 🟡
Duration 2.6 s 2.55 s 1.92% 🔼 🟢
Hitch time ratio 4 ms per s 3.92 ms per s 2.0% 🔼 🟢
Frame rate 75 fps 78.2 fps 4.27% 🔼 🟢
Number of hitches 1 1.2 -20.0% 🔽 🔴

@laevandus laevandus merged commit cf2d8c3 into develop Dec 23, 2024
14 checks passed
@laevandus laevandus deleted the fix/data-store-access branch December 23, 2024 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 Bug An issue or PR related to a bug 🌐 SDK: StreamChat (LLC) Tasks related to the StreamChat LLC SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants