fix(activity): summarize every loaded conversation instead of the first 5,000

This commit is contained in:
mesalogo
2026-10-04 03:07:16 +08:00
parent 29a134b804
commit 75e50fc194
2 changed files with 31 additions and 2 deletions
+24
View File
@@ -401,6 +401,30 @@ describe('activity history sync (paged)', () => {
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 () => {
const database = openDatabase()
database.replaceActivityHistory({ records: [record(), record()], legacyHistoryMayBeIncomplete: true })
+7 -2
View File
@@ -193,8 +193,13 @@ export async function refreshActivitySummary(
api: Pick<ActivityHistoryApi, 'summary'>
): Promise<void> {
const conversationIds = [...new Set(store.getPanel().records.map((record) => record.conversationId))]
.slice(0, MAX_SUMMARY_CONVERSATIONS)
store.setSummary(await api.summary({ conversationIds }))
// Every loaded conversation is summarized; large sets go in several requests.
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!)
}
/**