Skip to content

Commit

Permalink
fix: make group listing more performant
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Oct 8, 2024
1 parent 044a992 commit 07e8f93
Showing 1 changed file with 77 additions and 77 deletions.
154 changes: 77 additions & 77 deletions example/src/tests/groupPerformanceTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,83 @@ async function beforeAll(
)
}

test('testing large group listings with ordering', async () => {
await beforeAll(1000, 10, 10)

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`)

await groups[5].send({ text: `Alix message` })
await groups[50].send({ text: `Alix message` })
await groups[150].send({ text: `Alix message` })
await groups[500].send({ text: `Alix message` })
await groups[700].send({ text: `Alix message` })
await groups[900].send({ text: `Alix message` })

let start2 = Date.now()
let groups2 = await alixClient.conversations.listGroups(
{
members: false,
consentState: false,
description: false,
creatorInboxId: false,
addedByInboxId: false,
isActive: false,
lastMessage: true,
},
'lastMessage'
)
let end2 = Date.now()
console.log(`Alix loaded ${groups2.length} groups in ${end2 - start2}ms`)
assert(
end2 - start2 < end - start,
'listing 1000 groups without certain fields should take less time'
)

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`)

start = Date.now()
groups = await boClient.conversations.listGroups()
end = Date.now()
console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`)

start2 = Date.now()
groups2 = await boClient.conversations.listGroups(
{
members: false,
consentState: false,
description: false,
creatorInboxId: false,
addedByInboxId: false,
isActive: false,
lastMessage: true,
},
'lastMessage'
)
end2 = Date.now()
console.log(`Bo loaded ${groups2.length} groups in ${end2 - start2}ms`)
assert(
end2 - start2 < end - start,
'listing 1000 groups without certain fields should take less time'
)

return true
})

test('testing large group listings', async () => {
await beforeAll(1000)

Expand Down Expand Up @@ -224,83 +301,6 @@ test('testing large member listings', async () => {
return true
})

test('testing large group listings with ordering', async () => {
await beforeAll(1000, 10, 10)

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`)

await groups[5].send({ text: `Alix message` })
await groups[50].send({ text: `Alix message` })
await groups[150].send({ text: `Alix message` })
await groups[500].send({ text: `Alix message` })
await groups[700].send({ text: `Alix message` })
await groups[900].send({ text: `Alix message` })

let start2 = Date.now()
let groups2 = await alixClient.conversations.listGroups(
{
members: false,
consentState: false,
description: false,
creatorInboxId: false,
addedByInboxId: false,
isActive: false,
lastMessage: true,
},
'lastMessage'
)
let end2 = Date.now()
console.log(`Alix loaded ${groups2.length} groups in ${end2 - start2}ms`)
assert(
end2 - start2 < end - start,
'listing 1000 groups without certain fields should take less time'
)

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`)

start = Date.now()
groups = await boClient.conversations.listGroups()
end = Date.now()
console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`)

start2 = Date.now()
groups2 = await boClient.conversations.listGroups(
{
members: false,
consentState: false,
description: false,
creatorInboxId: false,
addedByInboxId: false,
isActive: false,
lastMessage: true,
},
'lastMessage'
)
end2 = Date.now()
console.log(`Bo loaded ${groups2.length} groups in ${end2 - start2}ms`)
assert(
end2 - start2 < end - start,
'listing 1000 groups without certain fields should take less time'
)

return true
})

test('testing sending message in large group', async () => {
await beforeAll(1, 2000, 100)

Expand Down

0 comments on commit 07e8f93

Please sign in to comment.