feat: 图片文字索引按时间分段优先处理最近图片

- 首次索引先处理最近 7 天,再依次回溯 30 天 / 近一年 / 更早历史
 - 完成后新到的图片单独补齐,不受历史回填影响
 - 覆盖度增加时间维度,可区分「最近已完整」与「更早仍在补齐」
This commit is contained in:
Wxw-Gu
2026-09-18 14:39:05 +08:00
parent 12b8fb34c6
commit 0f270366aa
15 changed files with 1917 additions and 183 deletions
@@ -86,8 +86,24 @@ function createHarness(): Harness {
const all = mixedMessages()
const imagesOnly = all.filter((message) => message.contentData?.type === 'image')
/**
* recent-first 之后,"读哪些行"由**时间分段**决定,所以夹具必须像真 WCDB 一样
* 按窗口说话。忽略窗口的夹具测不出调度行为,只会让"读了几次"变成 4 次。
*/
const inWindow = (
message: chat.FormattedMessage,
window?: { sinceMs?: number; beforeMs?: number }
): boolean => {
const createTimeMs = (message.createTime || 0) * 1000
if (window?.sinceMs !== undefined && createTimeMs < window.sinceMs) return false
if (window?.beforeMs !== undefined && createTimeMs >= window.beforeMs) return false
return true
}
const listMessages = vi.fn(async () => all)
const listImageMessages = vi.fn(async () => imagesOnly)
const listImageMessages = vi.fn(
async (_conversationId: string, window?: { sinceMs?: number; beforeMs?: number }) =>
imagesOnly.filter((message) => inWindow(message, window))
)
const service = new ImageTextIndexService()
service.bind({
@@ -98,7 +114,13 @@ function createHarness(): Harness {
listContacts: async () => [
{ md5: CONVERSATION, m_nsUsrName: 'boundary', type: 'user' as const }
],
countConversationImages: async () => ({ count: IMAGE_COUNT, typeColumn: 'local_type' }),
countConversationImages: async (
_conversationId: string,
window?: { sinceMs?: number; beforeMs?: number }
) => ({
count: imagesOnly.filter((message) => inWindow(message, window)).length,
typeColumn: 'local_type'
}),
imageWatermark: async () => ({ count: IMAGE_COUNT, maxLocalId: TEXT_COUNT + IMAGE_COUNT }),
listMessages,
listImageMessages,