-
Notifications
You must be signed in to change notification settings - Fork 21
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
Encode groups and conversations sequentially to fix iOS pool errors #462
Changes from 3 commits
8c597e9
913a6a0
b7f91b7
be21834
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 |
---|---|---|
|
@@ -400,44 +400,31 @@ public class XMTPModule: Module { | |
} | ||
|
||
let conversations = try await client.conversations.list() | ||
|
||
return try await withThrowingTaskGroup(of: String.self) { group in | ||
for conversation in conversations { | ||
group.addTask { | ||
await self.conversationsManager.set(conversation.cacheKey(inboxId), conversation) | ||
return try ConversationWrapper.encode(conversation, client: client) | ||
} | ||
} | ||
|
||
var results: [String] = [] | ||
for try await result in group { | ||
results.append(result) | ||
} | ||
|
||
return results | ||
|
||
var results: [String] = [] | ||
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. Went ahead and removed TaskGroup from listAll and listConversations since it could lead to similar issues with too many db connections, and I did not observe any slowdown in the test for loading 2000 conversations. before the change I saw " |
||
for conversation in conversations { | ||
await self.conversationsManager.set(conversation.cacheKey(inboxId), conversation) | ||
let encodedConversation = try ConversationWrapper.encode(conversation, client: client) | ||
results.append(encodedConversation) | ||
} | ||
|
||
return results | ||
} | ||
|
||
AsyncFunction("listGroups") { (inboxId: String) -> [String] in | ||
guard let client = await clientsManager.getClient(key: inboxId) else { | ||
throw Error.noClient | ||
} | ||
let groupList = try await client.conversations.groups() | ||
return try await withThrowingTaskGroup(of: String.self) { taskGroup in | ||
for group in groupList { | ||
taskGroup.addTask { | ||
await self.groupsManager.set(group.cacheKey(inboxId), group) | ||
return try GroupWrapper.encode(group, client: client) | ||
} | ||
} | ||
|
||
var results: [String] = [] | ||
for try await result in taskGroup { | ||
results.append(result) | ||
} | ||
|
||
return results | ||
|
||
var results: [String] = [] | ||
for group in groupList { | ||
await self.groupsManager.set(group.cacheKey(inboxId), group) | ||
let encodedGroup = try GroupWrapper.encode(group, client: client) | ||
results.append(encodedGroup) | ||
} | ||
|
||
return results | ||
} | ||
|
||
AsyncFunction("listAll") { (inboxId: String) -> [String] in | ||
|
@@ -446,21 +433,14 @@ public class XMTPModule: Module { | |
} | ||
let conversationContainerList = try await client.conversations.list(includeGroups: true) | ||
|
||
return try await withThrowingTaskGroup(of: String.self) { taskGroup in | ||
for conversation in conversationContainerList { | ||
taskGroup.addTask { | ||
await self.conversationsManager.set(conversation.cacheKey(inboxId), conversation) | ||
return try ConversationContainerWrapper.encode(conversation, client: client) | ||
} | ||
} | ||
|
||
var results: [String] = [] | ||
for try await result in taskGroup { | ||
results.append(result) | ||
} | ||
|
||
return results | ||
var results: [String] = [] | ||
for conversation in conversationContainerList { | ||
await self.conversationsManager.set(conversation.cacheKey(inboxId), conversation) | ||
let encodedConversationContainer = try ConversationContainerWrapper.encode(conversation, client: client) | ||
results.append(encodedConversationContainer) | ||
} | ||
|
||
return results | ||
} | ||
|
||
AsyncFunction("loadMessages") { (inboxId: String, topic: String, limit: Int?, before: Double?, after: Double?, direction: String?) -> [String] in | ||
|
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.
Expected to be deleted?
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.
yea, these tests were initially just documenting different behaviors between iOS and Android, but looking at them now, they just pass / fail randomly based off random order that groups are returned. tldr, dont think these tests are useful at the moment, and are just creating extra noise, in my opinion, as the person who wrote them :-P