From c8433664ffcb4194d64d2def3719348ee9aa6b8e Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 21 Oct 2024 12:30:10 -0700 Subject: [PATCH 1/5] add test --- example/src/tests/groupPerformanceTests.ts | 431 +++++++++++---------- 1 file changed, 220 insertions(+), 211 deletions(-) diff --git a/example/src/tests/groupPerformanceTests.ts b/example/src/tests/groupPerformanceTests.ts index 144e71038..89815d271 100644 --- a/example/src/tests/groupPerformanceTests.ts +++ b/example/src/tests/groupPerformanceTests.ts @@ -106,6 +106,15 @@ test('testing large group listings with ordering', async () => { end = Date.now() console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) + start = Date.now() + await boClient.conversations.syncAllGroups() + end = Date.now() + console.log(`Bo synced all ${groups.length} groups in ${end - start}ms`) + assert( + end - start < 3000, + 'Syncing all 1000 groups should take less than a 3 second' + ) + start = Date.now() groups = await boClient.conversations.listGroups() end = Date.now() @@ -134,214 +143,214 @@ test('testing large group listings with ordering', async () => { return true }) -test('testing large group listings', async () => { - await beforeAll(1000) - - let start = Date.now() - let groups = await alixClient.conversations.listGroups() - let end = Date.now() - console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) - assert( - end - start < 3000, - 'listing 1000 groups should take less than a 3 second' - ) - - start = Date.now() - await alixClient.conversations.syncGroups() - end = Date.now() - console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) - assert( - end - start < 100, - 'syncing 1000 cached groups should take less than a .1 second' - ) - - start = Date.now() - await boClient.conversations.syncGroups() - end = Date.now() - console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) - assert( - end - start < 6000, - 'syncing 1000 groups should take less than a 6 second' - ) - - start = Date.now() - groups = await boClient.conversations.listGroups() - end = Date.now() - console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) - assert( - end - start < 3000, - 'loading 1000 groups should take less than a 3 second' - ) - - return true -}) - -test('testing large message listings', async () => { - await beforeAll(1, 2000) - - const alixGroup = initialGroups[0] - let start = Date.now() - let messages = await alixGroup.messages() - let end = Date.now() - console.log(`Alix loaded ${messages.length} messages in ${end - start}ms`) - assert( - end - start < 1000, - 'listing 2000 self messages should take less than a 1 second' - ) - - start = Date.now() - await alixGroup.sync() - end = Date.now() - console.log(`Alix synced ${messages.length} messages in ${end - start}ms`) - assert( - end - start < 100, - 'syncing 2000 self messages should take less than a .1 second' - ) - - await boClient.conversations.syncGroups() - const boGroup = await boClient.conversations.findGroup(alixGroup.id) - start = Date.now() - await boGroup!.sync() - end = Date.now() - console.log(`Bo synced ${messages.length} messages in ${end - start}ms`) - assert( - end - start < 3000, - 'syncing 2000 messages should take less than a 3 second' - ) - - start = Date.now() - messages = await boGroup!.messages() - end = Date.now() - console.log(`Bo loaded ${messages.length} messages in ${end - start}ms`) - assert( - end - start < 1000, - 'loading 2000 messages should take less than a 1 second' - ) - - return true -}) - -test('testing large member listings', async () => { - await beforeAll(1, 1, 50) - - const alixGroup = initialGroups[0] - let start = Date.now() - let members = await alixGroup.members - let end = Date.now() - console.log(`Alix loaded ${members.length} members in ${end - start}ms`) - assert( - end - start < 100, - 'listing 50 members should take less than a .1 second' - ) - - start = Date.now() - await alixGroup.sync() - end = Date.now() - console.log(`Alix synced ${members.length} members in ${end - start}ms`) - assert( - end - start < 100, - 'syncing 50 members should take less than a .1 second' - ) - - await boClient.conversations.syncGroups() - const boGroup = await boClient.conversations.findGroup(alixGroup.id) - start = Date.now() - await boGroup!.sync() - end = Date.now() - console.log(`Bo synced ${members.length} members in ${end - start}ms`) - assert( - end - start < 100, - 'syncing 50 members should take less than a .1 second' - ) - - start = Date.now() - members = await boGroup!.members - end = Date.now() - console.log(`Bo loaded ${members.length} members in ${end - start}ms`) - assert( - end - start < 100, - 'loading 50 members should take less than a .1 second' - ) - - const [davonClient] = await createClients(1) - - start = Date.now() - await alixGroup.addMembers([davonClient.address]) - end = Date.now() - console.log(`Alix added 1 member in ${end - start}ms`) - assert(end - start < 100, 'adding 1 member should take less than a .1 second') - - start = Date.now() - members = await alixGroup.members - end = Date.now() - console.log(`Alix loaded ${members.length} members in ${end - start}ms`) - assert( - end - start < 100, - 'loading 50 member should take less than a .1 second' - ) - - start = Date.now() - await boGroup!.sync() - end = Date.now() - console.log(`Bo synced ${members.length} members in ${end - start}ms`) - assert( - end - start < 100, - 'syncing 50 member should take less than a .1 second' - ) - - start = Date.now() - members = await boGroup!.members - end = Date.now() - console.log(`Bo loaded ${members.length} members in ${end - start}ms`) - assert( - end - start < 100, - 'loading 50 member should take less than a .1 second' - ) - - return true -}) - -test('testing sending message in large group', async () => { - await beforeAll(1, 2000, 100) - - const alixGroup = initialGroups[0] - let start = Date.now() - await alixGroup.send({ text: `Alix message` }) - let end = Date.now() - console.log(`Alix sent a message in ${end - start}ms`) - assert( - end - start < 200, - 'sending a message should take less than a .2 second' - ) - - await boClient.conversations.syncGroups() - const boGroup = await boClient.conversations.findGroup(alixGroup.id) - start = Date.now() - await boGroup!.prepareMessage({ text: `Bo message` }) - end = Date.now() - console.log(`Bo sent a message in ${end - start}ms`) - assert( - end - start < 100, - 'preparing a message should take less than a .1 second' - ) - - start = Date.now() - await boGroup!.sync() - end = Date.now() - console.log(`Bo synced messages in ${end - start}ms`) - assert( - end - start < 9000, - 'syncing 2000 messages should take less than a 9 second' - ) - - start = Date.now() - await boGroup!.send({ text: `Bo message 2` }) - end = Date.now() - console.log(`Bo sent a message in ${end - start}ms`) - assert( - end - start < 100, - 'sending a message should take less than a .1 second' - ) - - return true -}) +// test('testing large group listings', async () => { +// await beforeAll(1000) + +// let start = Date.now() +// let groups = await alixClient.conversations.listGroups() +// let end = Date.now() +// console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) +// assert( +// end - start < 3000, +// 'listing 1000 groups should take less than a 3 second' +// ) + +// start = Date.now() +// await alixClient.conversations.syncGroups() +// end = Date.now() +// console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) +// assert( +// end - start < 100, +// 'syncing 1000 cached groups should take less than a .1 second' +// ) + +// start = Date.now() +// await boClient.conversations.syncGroups() +// end = Date.now() +// console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) +// assert( +// end - start < 6000, +// 'syncing 1000 groups should take less than a 6 second' +// ) + +// start = Date.now() +// groups = await boClient.conversations.listGroups() +// end = Date.now() +// console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) +// assert( +// end - start < 3000, +// 'loading 1000 groups should take less than a 3 second' +// ) + +// return true +// }) + +// test('testing large message listings', async () => { +// await beforeAll(1, 2000) + +// const alixGroup = initialGroups[0] +// let start = Date.now() +// let messages = await alixGroup.messages() +// let end = Date.now() +// console.log(`Alix loaded ${messages.length} messages in ${end - start}ms`) +// assert( +// end - start < 1000, +// 'listing 2000 self messages should take less than a 1 second' +// ) + +// start = Date.now() +// await alixGroup.sync() +// end = Date.now() +// console.log(`Alix synced ${messages.length} messages in ${end - start}ms`) +// assert( +// end - start < 100, +// 'syncing 2000 self messages should take less than a .1 second' +// ) + +// await boClient.conversations.syncGroups() +// const boGroup = await boClient.conversations.findGroup(alixGroup.id) +// start = Date.now() +// await boGroup!.sync() +// end = Date.now() +// console.log(`Bo synced ${messages.length} messages in ${end - start}ms`) +// assert( +// end - start < 3000, +// 'syncing 2000 messages should take less than a 3 second' +// ) + +// start = Date.now() +// messages = await boGroup!.messages() +// end = Date.now() +// console.log(`Bo loaded ${messages.length} messages in ${end - start}ms`) +// assert( +// end - start < 1000, +// 'loading 2000 messages should take less than a 1 second' +// ) + +// return true +// }) + +// test('testing large member listings', async () => { +// await beforeAll(1, 1, 50) + +// const alixGroup = initialGroups[0] +// let start = Date.now() +// let members = await alixGroup.members +// let end = Date.now() +// console.log(`Alix loaded ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'listing 50 members should take less than a .1 second' +// ) + +// start = Date.now() +// await alixGroup.sync() +// end = Date.now() +// console.log(`Alix synced ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'syncing 50 members should take less than a .1 second' +// ) + +// await boClient.conversations.syncGroups() +// const boGroup = await boClient.conversations.findGroup(alixGroup.id) +// start = Date.now() +// await boGroup!.sync() +// end = Date.now() +// console.log(`Bo synced ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'syncing 50 members should take less than a .1 second' +// ) + +// start = Date.now() +// members = await boGroup!.members +// end = Date.now() +// console.log(`Bo loaded ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'loading 50 members should take less than a .1 second' +// ) + +// const [davonClient] = await createClients(1) + +// start = Date.now() +// await alixGroup.addMembers([davonClient.address]) +// end = Date.now() +// console.log(`Alix added 1 member in ${end - start}ms`) +// assert(end - start < 100, 'adding 1 member should take less than a .1 second') + +// start = Date.now() +// members = await alixGroup.members +// end = Date.now() +// console.log(`Alix loaded ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'loading 50 member should take less than a .1 second' +// ) + +// start = Date.now() +// await boGroup!.sync() +// end = Date.now() +// console.log(`Bo synced ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'syncing 50 member should take less than a .1 second' +// ) + +// start = Date.now() +// members = await boGroup!.members +// end = Date.now() +// console.log(`Bo loaded ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'loading 50 member should take less than a .1 second' +// ) + +// return true +// }) + +// test('testing sending message in large group', async () => { +// await beforeAll(1, 2000, 100) + +// const alixGroup = initialGroups[0] +// let start = Date.now() +// await alixGroup.send({ text: `Alix message` }) +// let end = Date.now() +// console.log(`Alix sent a message in ${end - start}ms`) +// assert( +// end - start < 200, +// 'sending a message should take less than a .2 second' +// ) + +// await boClient.conversations.syncGroups() +// const boGroup = await boClient.conversations.findGroup(alixGroup.id) +// start = Date.now() +// await boGroup!.prepareMessage({ text: `Bo message` }) +// end = Date.now() +// console.log(`Bo sent a message in ${end - start}ms`) +// assert( +// end - start < 100, +// 'preparing a message should take less than a .1 second' +// ) + +// start = Date.now() +// await boGroup!.sync() +// end = Date.now() +// console.log(`Bo synced messages in ${end - start}ms`) +// assert( +// end - start < 9000, +// 'syncing 2000 messages should take less than a 9 second' +// ) + +// start = Date.now() +// await boGroup!.send({ text: `Bo message 2` }) +// end = Date.now() +// console.log(`Bo sent a message in ${end - start}ms`) +// assert( +// end - start < 100, +// 'sending a message should take less than a .1 second' +// ) + +// return true +// }) From a5d7bb2985ad8e417f4cab0182ec6c09fbfc4305 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 21 Oct 2024 12:30:59 -0700 Subject: [PATCH 2/5] add back limit --- .../src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt | 2 +- .../expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt | 2 +- ios/Wrappers/GroupWrapper.swift | 2 +- ios/XMTPModule.swift | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index ffe23e466..750b6c52c 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -635,7 +635,7 @@ class XMTPModule : Module() { val sortedGroupList = if (order == ConversationOrder.LAST_MESSAGE) { client.conversations.listGroups() .sortedByDescending { group -> - group.decryptedMessages().firstOrNull()?.sentAt + group.decryptedMessages(limit = 1).firstOrNull()?.sentAt } .let { groups -> if (limit != null && limit > 0) groups.take(limit) else groups diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt index 5fdb142af..b75c58c4f 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt @@ -37,7 +37,7 @@ class GroupWrapper { put("consentState", consentStateToString(group.consentState())) } if (groupParams.lastMessage) { - val lastMessage = group.decryptedMessages().firstOrNull() + val lastMessage = group.decryptedMessages(limit = 1).firstOrNull() if (lastMessage != null) { put("lastMessage", DecodedMessageWrapper.encode(lastMessage)) } diff --git a/ios/Wrappers/GroupWrapper.swift b/ios/Wrappers/GroupWrapper.swift index f00f73aeb..928fdd6d5 100644 --- a/ios/Wrappers/GroupWrapper.swift +++ b/ios/Wrappers/GroupWrapper.swift @@ -48,7 +48,7 @@ struct GroupWrapper { result["consentState"] = ConsentWrapper.consentStateToString(state: try group.consentState()) } if groupParams.lastMessage { - if let lastMessage = try await group.decryptedMessages().first { + if let lastMessage = try await group.decryptedMessages(limit: 1).first { result["lastMessage"] = try DecodedMessageWrapper.encode(lastMessage, client: client) } } diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 90d278617..ecaeb5d8d 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -547,7 +547,7 @@ public class XMTPModule: Module { var groupsWithMessages: [(Group, Date)] = [] for group in groups { do { - let firstMessage = try await group.decryptedMessages().first + let firstMessage = try await group.decryptedMessages(limit: 1).first let sentAt = firstMessage?.sentAt ?? Date.distantPast groupsWithMessages.append((group, sentAt)) } catch { From 7d762b698c1b4e5bc8fc84a25f52dc93acdaffaa Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 24 Oct 2024 17:17:18 -0700 Subject: [PATCH 3/5] remove double sync all --- .../src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 1b0104bd9..e8476ed6a 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -1092,7 +1092,6 @@ class XMTPModule : Module() { withContext(Dispatchers.IO) { logV("syncAllGroups") val client = clients[inboxId] ?: throw XMTPException("No client") - client.conversations.syncAllGroups() // Expo Modules do not support UInt, so we need to convert to Int val numGroupsSyncedInt: Int = client.conversations.syncAllGroups()?.toInt() ?: throw IllegalArgumentException( From 2997c53772953488df44ac7e2079c26aadd7738c Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 24 Oct 2024 17:39:20 -0700 Subject: [PATCH 4/5] add a test for it --- example/src/tests/groupPerformanceTests.ts | 426 ++++++++++----------- 1 file changed, 213 insertions(+), 213 deletions(-) diff --git a/example/src/tests/groupPerformanceTests.ts b/example/src/tests/groupPerformanceTests.ts index 89815d271..201a09bbb 100644 --- a/example/src/tests/groupPerformanceTests.ts +++ b/example/src/tests/groupPerformanceTests.ts @@ -111,8 +111,8 @@ test('testing large group listings with ordering', async () => { end = Date.now() console.log(`Bo synced all ${groups.length} groups in ${end - start}ms`) assert( - end - start < 3000, - 'Syncing all 1000 groups should take less than a 3 second' + end - start < 30000, + 'Syncing all 1000 groups should take less than a 30 second' ) start = Date.now() @@ -143,214 +143,214 @@ test('testing large group listings with ordering', async () => { return true }) -// test('testing large group listings', async () => { -// await beforeAll(1000) - -// let start = Date.now() -// let groups = await alixClient.conversations.listGroups() -// let end = Date.now() -// console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) -// assert( -// end - start < 3000, -// 'listing 1000 groups should take less than a 3 second' -// ) - -// start = Date.now() -// await alixClient.conversations.syncGroups() -// end = Date.now() -// console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) -// assert( -// end - start < 100, -// 'syncing 1000 cached groups should take less than a .1 second' -// ) - -// start = Date.now() -// await boClient.conversations.syncGroups() -// end = Date.now() -// console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) -// assert( -// end - start < 6000, -// 'syncing 1000 groups should take less than a 6 second' -// ) - -// start = Date.now() -// groups = await boClient.conversations.listGroups() -// end = Date.now() -// console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) -// assert( -// end - start < 3000, -// 'loading 1000 groups should take less than a 3 second' -// ) - -// return true -// }) - -// test('testing large message listings', async () => { -// await beforeAll(1, 2000) - -// const alixGroup = initialGroups[0] -// let start = Date.now() -// let messages = await alixGroup.messages() -// let end = Date.now() -// console.log(`Alix loaded ${messages.length} messages in ${end - start}ms`) -// assert( -// end - start < 1000, -// 'listing 2000 self messages should take less than a 1 second' -// ) - -// start = Date.now() -// await alixGroup.sync() -// end = Date.now() -// console.log(`Alix synced ${messages.length} messages in ${end - start}ms`) -// assert( -// end - start < 100, -// 'syncing 2000 self messages should take less than a .1 second' -// ) - -// await boClient.conversations.syncGroups() -// const boGroup = await boClient.conversations.findGroup(alixGroup.id) -// start = Date.now() -// await boGroup!.sync() -// end = Date.now() -// console.log(`Bo synced ${messages.length} messages in ${end - start}ms`) -// assert( -// end - start < 3000, -// 'syncing 2000 messages should take less than a 3 second' -// ) - -// start = Date.now() -// messages = await boGroup!.messages() -// end = Date.now() -// console.log(`Bo loaded ${messages.length} messages in ${end - start}ms`) -// assert( -// end - start < 1000, -// 'loading 2000 messages should take less than a 1 second' -// ) - -// return true -// }) - -// test('testing large member listings', async () => { -// await beforeAll(1, 1, 50) - -// const alixGroup = initialGroups[0] -// let start = Date.now() -// let members = await alixGroup.members -// let end = Date.now() -// console.log(`Alix loaded ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'listing 50 members should take less than a .1 second' -// ) - -// start = Date.now() -// await alixGroup.sync() -// end = Date.now() -// console.log(`Alix synced ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'syncing 50 members should take less than a .1 second' -// ) - -// await boClient.conversations.syncGroups() -// const boGroup = await boClient.conversations.findGroup(alixGroup.id) -// start = Date.now() -// await boGroup!.sync() -// end = Date.now() -// console.log(`Bo synced ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'syncing 50 members should take less than a .1 second' -// ) - -// start = Date.now() -// members = await boGroup!.members -// end = Date.now() -// console.log(`Bo loaded ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'loading 50 members should take less than a .1 second' -// ) - -// const [davonClient] = await createClients(1) - -// start = Date.now() -// await alixGroup.addMembers([davonClient.address]) -// end = Date.now() -// console.log(`Alix added 1 member in ${end - start}ms`) -// assert(end - start < 100, 'adding 1 member should take less than a .1 second') - -// start = Date.now() -// members = await alixGroup.members -// end = Date.now() -// console.log(`Alix loaded ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'loading 50 member should take less than a .1 second' -// ) - -// start = Date.now() -// await boGroup!.sync() -// end = Date.now() -// console.log(`Bo synced ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'syncing 50 member should take less than a .1 second' -// ) - -// start = Date.now() -// members = await boGroup!.members -// end = Date.now() -// console.log(`Bo loaded ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'loading 50 member should take less than a .1 second' -// ) - -// return true -// }) - -// test('testing sending message in large group', async () => { -// await beforeAll(1, 2000, 100) - -// const alixGroup = initialGroups[0] -// let start = Date.now() -// await alixGroup.send({ text: `Alix message` }) -// let end = Date.now() -// console.log(`Alix sent a message in ${end - start}ms`) -// assert( -// end - start < 200, -// 'sending a message should take less than a .2 second' -// ) - -// await boClient.conversations.syncGroups() -// const boGroup = await boClient.conversations.findGroup(alixGroup.id) -// start = Date.now() -// await boGroup!.prepareMessage({ text: `Bo message` }) -// end = Date.now() -// console.log(`Bo sent a message in ${end - start}ms`) -// assert( -// end - start < 100, -// 'preparing a message should take less than a .1 second' -// ) - -// start = Date.now() -// await boGroup!.sync() -// end = Date.now() -// console.log(`Bo synced messages in ${end - start}ms`) -// assert( -// end - start < 9000, -// 'syncing 2000 messages should take less than a 9 second' -// ) - -// start = Date.now() -// await boGroup!.send({ text: `Bo message 2` }) -// end = Date.now() -// console.log(`Bo sent a message in ${end - start}ms`) -// assert( -// end - start < 100, -// 'sending a message should take less than a .1 second' -// ) - -// return true -// }) +test('testing large group listings', async () => { + await beforeAll(1000) + + let start = Date.now() + let groups = await alixClient.conversations.listGroups() + let end = Date.now() + console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) + assert( + end - start < 3000, + 'listing 1000 groups should take less than a 3 second' + ) + + start = Date.now() + await alixClient.conversations.syncGroups() + end = Date.now() + console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) + assert( + end - start < 100, + 'syncing 1000 cached groups should take less than a .1 second' + ) + + start = Date.now() + await boClient.conversations.syncGroups() + end = Date.now() + console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) + assert( + end - start < 6000, + 'syncing 1000 groups should take less than a 6 second' + ) + + start = Date.now() + groups = await boClient.conversations.listGroups() + end = Date.now() + console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) + assert( + end - start < 3000, + 'loading 1000 groups should take less than a 3 second' + ) + + return true +}) + +test('testing large message listings', async () => { + await beforeAll(1, 2000) + + const alixGroup = initialGroups[0] + let start = Date.now() + let messages = await alixGroup.messages() + let end = Date.now() + console.log(`Alix loaded ${messages.length} messages in ${end - start}ms`) + assert( + end - start < 1000, + 'listing 2000 self messages should take less than a 1 second' + ) + + start = Date.now() + await alixGroup.sync() + end = Date.now() + console.log(`Alix synced ${messages.length} messages in ${end - start}ms`) + assert( + end - start < 100, + 'syncing 2000 self messages should take less than a .1 second' + ) + + await boClient.conversations.syncGroups() + const boGroup = await boClient.conversations.findGroup(alixGroup.id) + start = Date.now() + await boGroup!.sync() + end = Date.now() + console.log(`Bo synced ${messages.length} messages in ${end - start}ms`) + assert( + end - start < 3000, + 'syncing 2000 messages should take less than a 3 second' + ) + + start = Date.now() + messages = await boGroup!.messages() + end = Date.now() + console.log(`Bo loaded ${messages.length} messages in ${end - start}ms`) + assert( + end - start < 1000, + 'loading 2000 messages should take less than a 1 second' + ) + + return true +}) + +test('testing large member listings', async () => { + await beforeAll(1, 1, 50) + + const alixGroup = initialGroups[0] + let start = Date.now() + let members = await alixGroup.members + let end = Date.now() + console.log(`Alix loaded ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'listing 50 members should take less than a .1 second' + ) + + start = Date.now() + await alixGroup.sync() + end = Date.now() + console.log(`Alix synced ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'syncing 50 members should take less than a .1 second' + ) + + await boClient.conversations.syncGroups() + const boGroup = await boClient.conversations.findGroup(alixGroup.id) + start = Date.now() + await boGroup!.sync() + end = Date.now() + console.log(`Bo synced ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'syncing 50 members should take less than a .1 second' + ) + + start = Date.now() + members = await boGroup!.members + end = Date.now() + console.log(`Bo loaded ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'loading 50 members should take less than a .1 second' + ) + + const [davonClient] = await createClients(1) + + start = Date.now() + await alixGroup.addMembers([davonClient.address]) + end = Date.now() + console.log(`Alix added 1 member in ${end - start}ms`) + assert(end - start < 100, 'adding 1 member should take less than a .1 second') + + start = Date.now() + members = await alixGroup.members + end = Date.now() + console.log(`Alix loaded ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'loading 50 member should take less than a .1 second' + ) + + start = Date.now() + await boGroup!.sync() + end = Date.now() + console.log(`Bo synced ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'syncing 50 member should take less than a .1 second' + ) + + start = Date.now() + members = await boGroup!.members + end = Date.now() + console.log(`Bo loaded ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'loading 50 member should take less than a .1 second' + ) + + return true +}) + +test('testing sending message in large group', async () => { + await beforeAll(1, 2000, 100) + + const alixGroup = initialGroups[0] + let start = Date.now() + await alixGroup.send({ text: `Alix message` }) + let end = Date.now() + console.log(`Alix sent a message in ${end - start}ms`) + assert( + end - start < 200, + 'sending a message should take less than a .2 second' + ) + + await boClient.conversations.syncGroups() + const boGroup = await boClient.conversations.findGroup(alixGroup.id) + start = Date.now() + await boGroup!.prepareMessage({ text: `Bo message` }) + end = Date.now() + console.log(`Bo sent a message in ${end - start}ms`) + assert( + end - start < 100, + 'preparing a message should take less than a .1 second' + ) + + start = Date.now() + await boGroup!.sync() + end = Date.now() + console.log(`Bo synced messages in ${end - start}ms`) + assert( + end - start < 9000, + 'syncing 2000 messages should take less than a 9 second' + ) + + start = Date.now() + await boGroup!.send({ text: `Bo message 2` }) + end = Date.now() + console.log(`Bo sent a message in ${end - start}ms`) + assert( + end - start < 100, + 'sending a message should take less than a .1 second' + ) + + return true +}) From c4f0d4e30955b0d5ecbadf649eded66983ea0fc7 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 24 Oct 2024 17:40:53 -0700 Subject: [PATCH 5/5] fix: only call sync all once