( searchSettings: SerializedSearchSettings, account: accounts, logger: Logger )
| 32 | } |
| 33 | |
| 34 | async function syncUpdatedThreads( |
| 35 | searchSettings: SerializedSearchSettings, |
| 36 | account: accounts, |
| 37 | logger: Logger |
| 38 | ) { |
| 39 | let cursor = new Date(searchSettings.lastSync || 0); |
| 40 | let stats = 0; |
| 41 | do { |
| 42 | const messages = await prisma.messages.findMany({ |
| 43 | select: { threadId: true, updatedAt: true }, |
| 44 | where: { |
| 45 | threads: { |
| 46 | ...threadsWhere({ accountId: account.id }), |
| 47 | }, |
| 48 | updatedAt: { gt: cursor }, |
| 49 | }, |
| 50 | orderBy: { updatedAt: 'asc' }, |
| 51 | take: 10, |
| 52 | }); |
| 53 | |
| 54 | const threads = await queryThreads({ |
| 55 | where: { |
| 56 | id: { in: [...new Set(messages.map((m) => m.threadId!))] }, |
| 57 | }, |
| 58 | }); |
| 59 | |
| 60 | if (!threads.length) { |
| 61 | break; |
| 62 | } |
| 63 | |
| 64 | stats += threads.length; |
| 65 | cursor = messages.at(messages.length - 1)?.updatedAt!; |
| 66 | |
| 67 | await pushToTypesense({ |
| 68 | threads, |
| 69 | is_restrict: searchSettings.scope === 'private', |
| 70 | logger, |
| 71 | anonymize: account.anonymizeUsers |
| 72 | ? (account.anonymize as AnonymizeType) |
| 73 | : undefined, |
| 74 | }); |
| 75 | } while (true); |
| 76 | logger.log({ syncUpdatedThreads: stats }); |
| 77 | } |
no test coverage detected