A decentralized music tracking and discovery platform built on AT Protocol 🎵

refactor: streamline album processing logic and enhance logging in Meilisearch sync

+20 -14
+4 -3
apps/api/src/scripts/genres.ts
··· 11 11 .from(tables.spotifyTokens) 12 12 .leftJoin( 13 13 tables.spotifyAccounts, 14 - eq(tables.spotifyAccounts.userId, tables.spotifyTokens.userId), 14 + eq(tables.spotifyAccounts.userId, tables.spotifyTokens.userId) 15 15 ) 16 16 .where(eq(tables.spotifyAccounts.isBetaUser, true)) 17 17 .execute() ··· 51 51 headers: { 52 52 Authorization: `Bearer ${token}`, 53 53 }, 54 - }, 54 + } 55 55 ) 56 56 .then( 57 57 (res) => ··· 64 64 images: Array<{ url: string }>; 65 65 }>; 66 66 }; 67 - }>, 67 + }> 68 68 ) 69 69 .then(async (data) => _.get(data, "artists.items.0")); 70 70 ··· 92 92 // wait for a while before retrying 93 93 await new Promise((resolve) => setTimeout(resolve, 1000)); 94 94 } 95 + // biome-ignore lint/correctness/noConstantCondition: true 95 96 } while (true); 96 97 97 98 // sleep for a while to avoid rate limiting
+16 -11
apps/api/src/scripts/meili.ts
··· 23 23 24 24 async function createAlbums() { 25 25 const { meilisearch } = ctx; 26 - const skip = 0; 27 26 const size = 100; 28 27 const total = await ctx.db 29 28 .select({ value: count() }) 30 29 .from(tables.albums) 31 30 .execute() 32 31 .then(([row]) => row.value); 33 - const results = await ctx.db 34 - .select() 35 - .from(tables.albums) 36 - .limit(size) 37 - .offset(skip) 38 - .execute(); 32 + for (let i = 0; i < total; i += size) { 33 + const skip = i; 34 + console.log( 35 + `Processing ${chalk.magentaBright("albums")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}` 36 + ); 37 + const results = await ctx.db 38 + .select() 39 + .from(tables.albums) 40 + .limit(size) 41 + .offset(skip) 42 + .execute(); 39 43 40 - await meilisearch.post(`indexes/albums/documents?primaryKey=id`, results); 44 + await meilisearch.post(`indexes/albums/documents?primaryKey=id`, results); 45 + } 41 46 } 42 47 43 48 async function createArtists() { ··· 51 56 for (let i = 0; i < total; i += size) { 52 57 const skip = i; 53 58 console.log( 54 - `Processing ${chalk.magentaBright("artists")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}`, 59 + `Processing ${chalk.magentaBright("artists")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}` 55 60 ); 56 61 const results = await ctx.db 57 62 .select() ··· 75 80 for (let i = 0; i < total; i += size) { 76 81 const skip = i; 77 82 console.log( 78 - `Processing ${chalk.magentaBright("tracks")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}`, 83 + `Processing ${chalk.magentaBright("tracks")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}` 79 84 ); 80 85 const results = await ctx.db 81 86 .select() ··· 100 105 for (let i = 0; i < total; i += size) { 101 106 const skip = i; 102 107 console.log( 103 - `Processing ${chalk.magentaBright("users")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}`, 108 + `Processing ${chalk.magentaBright("users")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}` 104 109 ); 105 110 const results = await ctx.db 106 111 .select()