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

Do not use view context in StreamChat #3550

Merged
merged 3 commits into from
Jan 4, 2025
Merged

Conversation

laevandus
Copy link
Contributor

@laevandus laevandus commented Jan 3, 2025

🔗 Issue Links

🎯 Goal

Do not use viewContext in LLC

📝 Summary

🛠 Implementation

We should use background context for reading and writableContext for writing. There is not need for viewContext anymore. Remove viewContext references from LLC (except DataContainer). Many of our tests still access viewContext.

🎨 Showcase

🧪 Manual Testing Notes

N/A

☑️ 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 the 🌐 SDK: StreamChat (LLC) Tasks related to the StreamChat LLC SDK label Jan 3, 2025
@laevandus laevandus requested a review from a team as a code owner January 3, 2025 12:29
let context = viewContext
let context = backgroundReadOnlyContext
Copy link
Contributor Author

@laevandus laevandus Jan 3, 2025

Choose a reason for hiding this comment

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

This was a mistake in PR:3541

Copy link

github-actions bot commented Jan 3, 2025

1 Message
📖 There seems to be app changes but CHANGELOG wasn't modified.
Please include an entry if the PR includes user-facing changes.
You can find it at CHANGELOG.md.

Generated by 🚫 Danger

Comment on lines -13 to 18
@MainActor public func makeConnectedUser() throws -> ConnectedUser {
let user = try CurrentUserDTO.load(context: databaseContainer.viewContext)
public func makeConnectedUser() throws -> ConnectedUser {
let user = try databaseContainer.readAndWait { session in
guard let dto = session.currentUser else { throw ClientError.CurrentUserDoesNotExist() }
return try dto.asModel()
}
return ConnectedUser(user: user, client: self)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All our other make methods do not require @MainActor, therefore we should skip it here as well. Downside is that this change would generate a warning that no await is needed if it was called outside of MainActor. Can we make this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, that's fine

@Stream-SDK-Bot
Copy link
Collaborator

SDK Size

title develop branch diff status
StreamChat 7.03 MB 7.03 MB 0 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 1.67 ms 83.3% 🔼 🟢
Duration 2.6 s 2.54 s 2.31% 🔼 🟢
Hitch time ratio 4 ms per s 0.65 ms per s 83.75% 🔼 🟢
Frame rate 75 fps 78.46 fps 4.61% 🔼 🟢
Number of hitches 1 0.2 80.0% 🔼 🟢

@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Jan 3, 2025

SDK Size

title develop branch diff status
StreamChat 6.98 MB 6.98 MB -1 KB 🚀
StreamChatUI 4.77 MB 4.77 MB 0 KB 🟢

Comment on lines -13 to 18
@MainActor public func makeConnectedUser() throws -> ConnectedUser {
let user = try CurrentUserDTO.load(context: databaseContainer.viewContext)
public func makeConnectedUser() throws -> ConnectedUser {
let user = try databaseContainer.readAndWait { session in
guard let dto = session.currentUser else { throw ClientError.CurrentUserDoesNotExist() }
return try dto.asModel()
}
return ConnectedUser(user: user, client: self)
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, that's fine

@laevandus laevandus merged commit e03357e into develop Jan 4, 2025
14 checks passed
@laevandus laevandus deleted the view-context-cleanup branch January 4, 2025 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌐 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