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

Function slugifyTask

packages/queue/src/tasks/slugify.ts:19–44  ·  view source on GitHub ↗
(logger: Logger)

Source from the content-addressed store, hash-verified

17};
18
19async function slugifyTask(logger: Logger) {
20 let skip = 0;
21 let threadsWithNoSlug = await findThreadsWithNoSlugs(skip);
22 logger.info({ threadsWithNoSlug: threadsWithNoSlug.length });
23
24 // weird case here when return 0 rows but there still more rows,
25 // need to re-execute the process a few times to be really completed
26 while (threadsWithNoSlug.length > 0) {
27 skip += 100;
28 const slugsTransaction = threadsWithNoSlug.map((t) => {
29 const message = t.messages[0];
30 const slug = createSlug(message?.body || '');
31 return prisma.threads.update({
32 where: {
33 id: t.id,
34 },
35 data: {
36 slug,
37 },
38 });
39 });
40 await prisma.$transaction(slugsTransaction);
41 threadsWithNoSlug = await findThreadsWithNoSlugs(skip);
42 logger.info({ threadsWithNoSlug: threadsWithNoSlug.length });
43 }
44}
45
46const findThreadsWithNoSlugs = (skip: number) => {
47 return prisma.threads.findMany({

Callers 1

slugifyFunction · 0.85

Calls 4

findThreadsWithNoSlugsFunction · 0.85
mapMethod · 0.80
infoMethod · 0.65
updateMethod · 0.45

Tested by

no test coverage detected