A decentralized music tracking and discovery platform built on AT Protocol 🎵 forked from rocksky.app/rocksky
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117import chalk from "chalk";import { ctx } from "context";import { count } from "drizzle-orm";import tables from "schema";
async function main() { console.log(chalk.cyan("Starting Meilisearch sync..."));
try { await Promise.all([ createAlbums(), createArtists(), createTracks(), createUsers(), ]); console.log(chalk.green("Meilisearch sync completed successfully.")); } catch (error) { console.error(chalk.red("Error during Meilisearch sync:"), error); }}
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();
await meilisearch.post(`indexes/albums/documents?primaryKey=id`, results);}
async function createArtists() { const { meilisearch } = ctx; const size = 100; const total = await ctx.db .select({ value: count() }) .from(tables.artists) .execute() .then(([row]) => row.value); 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)}`, ); const results = await ctx.db .select() .from(tables.artists) .limit(size) .offset(skip) .execute();
await meilisearch.post(`indexes/artists/documents?primaryKey=id`, results); }}
async function createTracks() { const { meilisearch } = ctx; const size = 100; const total = await ctx.db .select({ value: count() }) .from(tables.tracks) .execute() .then(([row]) => row.value); 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)}`, ); const results = await ctx.db .select() .from(tables.tracks) .limit(size) .offset(skip) .execute();
await meilisearch.post(`/indexes/tracks/documents?primaryKey=id`, results); }}
async function createUsers() { const { meilisearch } = ctx; const size = 100; const total = await ctx.db .select({ value: count() }) .from(tables.users) .execute() .then(([row]) => row.value);
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)}`, ); const results = await ctx.db .select() .from(tables.users) .limit(size) .offset(skip) .execute();
await meilisearch.post(`/indexes/users/documents?primaryKey=id`, results); }}
process.exit(0);