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