diff --git a/apps/api/src/scripts/genres.ts b/apps/api/src/scripts/genres.ts index 0ec319b5..35790a7f 100644 --- a/apps/api/src/scripts/genres.ts +++ b/apps/api/src/scripts/genres.ts @@ -11,7 +11,7 @@ async function getSpotifyToken(): Promise { .from(tables.spotifyTokens) .leftJoin( tables.spotifyAccounts, - eq(tables.spotifyAccounts.userId, tables.spotifyTokens.userId), + eq(tables.spotifyAccounts.userId, tables.spotifyTokens.userId) ) .where(eq(tables.spotifyAccounts.isBetaUser, true)) .execute() @@ -51,7 +51,7 @@ async function getGenresAndPicture(artists) { headers: { Authorization: `Bearer ${token}`, }, - }, + } ) .then( (res) => @@ -64,7 +64,7 @@ async function getGenresAndPicture(artists) { images: Array<{ url: string }>; }>; }; - }>, + }> ) .then(async (data) => _.get(data, "artists.items.0")); @@ -92,6 +92,7 @@ async function getGenresAndPicture(artists) { // wait for a while before retrying await new Promise((resolve) => setTimeout(resolve, 1000)); } + // biome-ignore lint/correctness/noConstantCondition: true } while (true); // sleep for a while to avoid rate limiting diff --git a/apps/api/src/scripts/meili.ts b/apps/api/src/scripts/meili.ts index 0e0cbe4a..61abfa0e 100644 --- a/apps/api/src/scripts/meili.ts +++ b/apps/api/src/scripts/meili.ts @@ -23,21 +23,26 @@ await main(); async function createAlbums() { const { meilisearch } = ctx; - const skip = 0; const size = 100; const total = await ctx.db .select({ value: count() }) .from(tables.albums) .execute() .then(([row]) => row.value); - const results = await ctx.db - .select() - .from(tables.albums) - .limit(size) - .offset(skip) - .execute(); + for (let i = 0; i < total; i += size) { + const skip = i; + console.log( + `Processing ${chalk.magentaBright("albums")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}` + ); + const results = await ctx.db + .select() + .from(tables.albums) + .limit(size) + .offset(skip) + .execute(); - await meilisearch.post(`indexes/albums/documents?primaryKey=id`, results); + await meilisearch.post(`indexes/albums/documents?primaryKey=id`, results); + } } async function createArtists() { @@ -51,7 +56,7 @@ async function createArtists() { for (let i = 0; i < total; i += size) { const skip = i; console.log( - `Processing ${chalk.magentaBright("artists")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}`, + `Processing ${chalk.magentaBright("artists")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}` ); const results = await ctx.db .select() @@ -75,7 +80,7 @@ async function createTracks() { for (let i = 0; i < total; i += size) { const skip = i; console.log( - `Processing ${chalk.magentaBright("tracks")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}`, + `Processing ${chalk.magentaBright("tracks")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}` ); const results = await ctx.db .select() @@ -100,7 +105,7 @@ async function createUsers() { for (let i = 0; i < total; i += size) { const skip = i; console.log( - `Processing ${chalk.magentaBright("users")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}`, + `Processing ${chalk.magentaBright("users")}: ${chalk.magentaBright(skip)} to ${chalk.magentaBright(skip + size)}` ); const results = await ctx.db .select()