A decentralized music tracking and discovery platform built on AT Protocol 馃幍 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
99
fork

Configure Feed

Select the types of activity you want to include in your feed.

at setup-tracing 116 lines 2.9 kB view raw
1import chalk from "chalk"; 2import { ctx } from "context"; 3import { count } from "drizzle-orm"; 4import tables from "schema"; 5 6async function main() { 7 console.log(chalk.cyan("Starting Meilisearch sync...")); 8 9 try { 10 await Promise.all([ 11 createAlbums(), 12 createArtists(), 13 createTracks(), 14 createUsers(), 15 ]); 16 console.log(chalk.green("Meilisearch sync completed successfully.")); 17 } catch (error) { 18 console.error(chalk.red("Error during Meilisearch sync:"), error); 19 } 20} 21 22await main(); 23 24async 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 43async function createArtists() { 44 const { meilisearch } = ctx; 45 const size = 100; 46 const total = await ctx.db 47 .select({ value: count() }) 48 .from(tables.artists) 49 .execute() 50 .then(([row]) => row.value); 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() 58 .from(tables.artists) 59 .limit(size) 60 .offset(skip) 61 .execute(); 62 63 await meilisearch.post(`indexes/artists/documents?primaryKey=id`, results); 64 } 65} 66 67async function createTracks() { 68 const { meilisearch } = ctx; 69 const size = 100; 70 const total = await ctx.db 71 .select({ value: count() }) 72 .from(tables.tracks) 73 .execute() 74 .then(([row]) => row.value); 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() 82 .from(tables.tracks) 83 .limit(size) 84 .offset(skip) 85 .execute(); 86 87 await meilisearch.post(`/indexes/tracks/documents?primaryKey=id`, results); 88 } 89} 90 91async function createUsers() { 92 const { meilisearch } = ctx; 93 const size = 100; 94 const total = await ctx.db 95 .select({ value: count() }) 96 .from(tables.users) 97 .execute() 98 .then(([row]) => row.value); 99 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() 107 .from(tables.users) 108 .limit(size) 109 .offset(skip) 110 .execute(); 111 112 await meilisearch.post(`/indexes/users/documents?primaryKey=id`, results); 113 } 114} 115 116process.exit(0);