-
Notifications
You must be signed in to change notification settings - Fork 913
Ensure getRootSpaceSummaries() is not called on the main thread.
#5835
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
Changes from 5 commits
cd06ba6
fb73628
d2eca73
abdfd9d
c542619
b2f9d67
da656ac
ebcab18
6b5822e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,6 @@ import kotlinx.coroutines.flow.combine | |
| import kotlinx.coroutines.flow.distinctUntilChanged | ||
| import kotlinx.coroutines.flow.flowOn | ||
| import kotlinx.coroutines.flow.launchIn | ||
| import kotlinx.coroutines.flow.map | ||
| import kotlinx.coroutines.flow.onEach | ||
| import kotlinx.coroutines.flow.sample | ||
| import kotlinx.coroutines.launch | ||
|
|
@@ -212,7 +211,8 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa | |
| } | ||
| session.coroutineScope.launch { | ||
| orderCommands.forEach { | ||
| session.getRoom(it.spaceId)?.updateAccountData(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER, | ||
| session.getRoom(it.spaceId)?.updateAccountData( | ||
| RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER, | ||
| SpaceOrderContent(order = it.order).toContent() | ||
| ) | ||
| } | ||
|
|
@@ -278,31 +278,23 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa | |
| displayName = QueryStringValue.IsNotEmpty | ||
| } | ||
|
|
||
| val flowSession = session.flow() | ||
|
|
||
| combine( | ||
| flowSession | ||
| .liveUser(session.myUserId) | ||
| .map { | ||
| it.getOrNull() | ||
| }, | ||
| flowSession | ||
| session.flow() | ||
| .liveSpaceSummaries(params), | ||
| session | ||
| .accountDataService() | ||
| session.accountDataService() | ||
| .getLiveRoomAccountDataEvents(setOf(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER)) | ||
| .asFlow() | ||
| ) { _, communityGroups, _ -> | ||
|
Comment on lines
+284
to
-295
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to double check, were the other flows being used as some sort of predicate? / Do we need it's a bit strange to see us submit flows to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's true that we ignore the result, but we want to be notified when the account data |
||
| communityGroups | ||
| ) { spaces, _ -> | ||
| spaces | ||
| } | ||
| .execute { async -> | ||
| val rootSpaces = session.spaceService().getRootSpaceSummaries() | ||
| val orders = rootSpaces.map { | ||
| val rootSpaces = async.invoke().orEmpty().filter { it.flattenParentIds.isEmpty() } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On my side this is equivalent, but I do not have any spaces with child space. I will create some
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, it works as expected |
||
| val orders = rootSpaces.associate { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 |
||
| it.roomId to session.getRoom(it.roomId) | ||
| ?.getAccountDataEvent(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER) | ||
| ?.content.toModel<SpaceOrderContent>() | ||
| ?.safeOrder() | ||
| }.toMap() | ||
| } | ||
| copy( | ||
| asyncSpaces = async, | ||
| rootSpacesOrdered = rootSpaces.sortedWith(TopLevelSpaceComparator(orders)), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
not for this PR as it would introduce lots of changes, but worth highlighting in case we want guard against other cases
from my understanding the general approach of coroutines scoping is to define the context switching at the lowest possible level, which in this case would be
we already have a similar wrapper for awaitTransaction
this would also force non coroutine based usages to rely on
runBlocking, which would have the benefit of make finding the usages a bit easierThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, good point!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we might want to dispatch querying db to a background thread, to avoid blocking the dispatcher, as Retrofit does for request (and probably Room)