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

Function buildPages

packages/pagination/src/buildPages.ts:5–52  ·  view source on GitHub ↗
(account: accounts)

Source from the content-addressed store, hash-verified

3const PAGE_SIZE = 30;
4
5export async function buildPages(account: accounts) {
6 const channels = await prisma.channels.findMany({
7 where: { accountId: account.id },
8 });
9
10 for (const channel of channels) {
11 let page = channel.pages || 1;
12 let keepLoop = true;
13
14 do {
15 const threads = await prisma.threads.findMany({
16 select: { id: true, sentAt: true },
17 where: {
18 channelId: channel.id,
19 page: null,
20 hidden: false,
21 messages: { some: {} },
22 },
23 orderBy: { sentAt: 'asc' },
24 take: PAGE_SIZE,
25 });
26
27 if (threads.length === PAGE_SIZE) {
28 await prisma.threads.updateMany({
29 data: { page },
30 where: { id: { in: threads.map((t) => t.id) } },
31 });
32
33 await prisma.channels.update({
34 data: {
35 pages: page,
36 lastPageBuildAt: threads[PAGE_SIZE - 1].sentAt,
37 },
38 where: { id: channel.id },
39 });
40 page++;
41 } else {
42 // latest, nothing to do
43 keepLoop = false;
44 }
45 // console.info(
46 // `${account.name || account.id} > ${channel.channelName || channel.id}`,
47 // { threads: threads.length, page, keepLoop }
48 // );
49 } while (keepLoop);
50 }
51 return account.name || account.id;
52}
53
54export async function cleanUp(accountId?: string) {
55 const accounts = await prisma.accounts.findMany({

Callers 2

runFunction · 0.90
createThreadsOneByDayFunction · 0.90

Calls 2

mapMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected