fix(activity): summarize every loaded conversation instead of the first 5,000
This commit is contained in:
@@ -401,6 +401,30 @@ describe('activity history sync (paged)', () => {
|
|||||||
sync.stop()
|
sync.stop()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('summarizes every loaded conversation, beyond one request', async () => {
|
||||||
|
const records = Array.from({ length: 5_003 }, (_, index) =>
|
||||||
|
record({ conversationId: `many-${index}`, kind: 'request', title: `Title ${index}`, status: 'completed' }))
|
||||||
|
const store = createActivityStore()
|
||||||
|
store.markReady()
|
||||||
|
store.setFirstPage('all', { records }, store.getGeneration())
|
||||||
|
store.refreshPanel()
|
||||||
|
const requested: number[] = []
|
||||||
|
await refreshActivitySummary(store, {
|
||||||
|
summary: async ({ conversationIds }) => {
|
||||||
|
requested.push(conversationIds.length)
|
||||||
|
return {
|
||||||
|
counts: { all: records.length, active: 0, failed: 0 },
|
||||||
|
conversations: Object.fromEntries(conversationIds.map((id) => [id, { title: id, status: 'completed' as const }])),
|
||||||
|
legacyHistoryMayBeIncomplete: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
expect(requested).toEqual([5_000, 3])
|
||||||
|
const conversations = store.getSummary()!.conversations
|
||||||
|
expect(Object.keys(conversations)).toHaveLength(5_003)
|
||||||
|
expect(conversations['many-5002']?.title).toBe('many-5002')
|
||||||
|
})
|
||||||
|
|
||||||
it('clear empties the database, the loaded pages and the summary', async () => {
|
it('clear empties the database, the loaded pages and the summary', async () => {
|
||||||
const database = openDatabase()
|
const database = openDatabase()
|
||||||
database.replaceActivityHistory({ records: [record(), record()], legacyHistoryMayBeIncomplete: true })
|
database.replaceActivityHistory({ records: [record(), record()], legacyHistoryMayBeIncomplete: true })
|
||||||
|
|||||||
@@ -193,8 +193,13 @@ export async function refreshActivitySummary(
|
|||||||
api: Pick<ActivityHistoryApi, 'summary'>
|
api: Pick<ActivityHistoryApi, 'summary'>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const conversationIds = [...new Set(store.getPanel().records.map((record) => record.conversationId))]
|
const conversationIds = [...new Set(store.getPanel().records.map((record) => record.conversationId))]
|
||||||
.slice(0, MAX_SUMMARY_CONVERSATIONS)
|
// Every loaded conversation is summarized; large sets go in several requests.
|
||||||
store.setSummary(await api.summary({ conversationIds }))
|
let merged: ActivityHistorySummary | undefined
|
||||||
|
for (let start = 0; start === 0 || start < conversationIds.length; start += MAX_SUMMARY_CONVERSATIONS) {
|
||||||
|
const part = await api.summary({ conversationIds: conversationIds.slice(start, start + MAX_SUMMARY_CONVERSATIONS) })
|
||||||
|
merged = merged ? { ...part, conversations: { ...merged.conversations, ...part.conversations } } : part
|
||||||
|
}
|
||||||
|
store.setSummary(merged!)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user