(logger: Logger)
| 17 | }; |
| 18 | |
| 19 | async 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 | |
| 46 | const findThreadsWithNoSlugs = (skip: number) => { |
| 47 | return prisma.threads.findMany({ |
no test coverage detected