WIP. A little custom music server
0
fork

Configure Feed

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

update sync to use inArray

+27 -4
+27 -4
backend/src/sync-library.ts
··· 1 1 import { Effect, Stream, Chunk, Console } from "effect"; 2 2 import { DatabaseLive } from "./db"; 3 3 import { readDirectory } from "./file-parser"; 4 + import { inArray } from "drizzle-orm"; 4 5 5 6 import { albumTable, artistTable, artistToAlbumTable, fileTable, songTable, songToArtistTable } from "./db/schema"; 6 7 import type { MetadataWithFilepathSchema } from "./metadata"; ··· 19 20 alreadyIndexed.map((x) => x.path), 20 21 ); 21 22 23 + let i = 0; 24 + 22 25 yield* stream.pipe( 23 26 Stream.tap((x) => 24 27 Console.log( ··· 32 35 colors.Reset, 33 36 ), 34 37 ), 38 + Stream.tap(() => { 39 + i++; 40 + return Effect.void; 41 + }), 35 42 Stream.grouped(10), 36 43 //Stream.schedule(Schedule.spaced("3 second")), 37 44 Stream.mapEffect(saveChunk, { concurrency: 5 }), 38 45 Stream.runDrain, 39 46 ); 47 + 48 + yield* Console.log(`Total found: ${i}`); 40 49 }); 41 50 42 51 const saveChunk = Effect.fn("save-chunk")(function* (chunk: Chunk.Chunk<Metadata>) { ··· 143 152 id: songTable.id, 144 153 title: songTable.title, 145 154 }) 146 - .from(songTable); 155 + .from(songTable) 156 + .where( 157 + inArray( 158 + songTable.fileId, 159 + newSongs.map((x) => x.fileId), 160 + ), 161 + ); 147 162 }); 148 163 149 164 const createFiles = Effect.fn("create-files")(function* (chunk: Chunk.Chunk<Metadata>) { ··· 164 179 id: fileTable.id, 165 180 filePath: fileTable.path, 166 181 }) 167 - .from(fileTable); 182 + .from(fileTable) 183 + .where( 184 + inArray( 185 + fileTable.path, 186 + newFiles.map((x) => x.path), 187 + ), 188 + ); 168 189 }); 169 190 170 191 const createArtists = Effect.fn("create-artists")(function* (chunk: Chunk.Chunk<Metadata>) { ··· 191 212 id: artistTable.id, 192 213 name: artistTable.name, 193 214 }) 194 - .from(artistTable); 215 + .from(artistTable) 216 + .where(inArray(artistTable.name, newArtists)); 195 217 }); 196 218 197 219 const createAlbums = Effect.fn("create-albums")(function* (chunk: Chunk.Chunk<Metadata>) { ··· 218 240 id: albumTable.id, 219 241 title: albumTable.title, 220 242 }) 221 - .from(albumTable); 243 + .from(albumTable) 244 + .where(inArray(albumTable.title, newAlbums)); 222 245 }); 223 246 224 247 function chunkToUniqueArray<T extends object, U extends string | readonly string[]>(