MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / syncUpdatedThreads

Function syncUpdatedThreads

packages/typesense/src/sync.ts:34–77  ·  view source on GitHub ↗
(
  searchSettings: SerializedSearchSettings,
  account: accounts,
  logger: Logger
)

Source from the content-addressed store, hash-verified

32}
33
34async 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}

Callers 1

syncFunction · 0.85

Calls 5

threadsWhereFunction · 0.90
queryThreadsFunction · 0.90
pushToTypesenseFunction · 0.90
mapMethod · 0.80
logMethod · 0.65

Tested by

no test coverage detected