A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

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

chore: scoped-tracks perf improvements

+26 -101
+26 -36
src/components/orchestrator/scoped-tracks/element.js
··· 8 8 9 9 /** 10 10 * @import {Track} from "@definitions/types.d.ts" 11 - * @import {ProxiedActions} from "@common/worker.d.ts" 12 11 * @import {InputElement} from "@components/input/types.d.ts" 13 12 * @import {OutputElement} from "@components/output/types.d.ts" 14 - * 15 - * @import {Actions} from "./types.d.ts" 16 13 */ 17 14 18 15 //////////////////////////////////////////// ··· 21 18 22 19 class ScopedTracksOrchestrator extends BroadcastableDiffuseElement { 23 20 static NAME = "diffuse/orchestrator/scoped-tracks"; 24 - static WORKER_URL = "components/orchestrator/scoped-tracks/worker.js"; 25 - 26 - /** @type {ProxiedActions<Actions>} */ 27 - #proxy; 28 - 29 - constructor() { 30 - super(); 31 - this.#proxy = this.workerProxy({ 32 - forceNew: { 33 - dependencies: { 34 - input: true, 35 - }, 36 - }, 37 - }); 38 - } 39 21 40 22 // SIGNALS 41 23 ··· 122 104 // Watch tracks collection 123 105 this.effect(async () => { 124 106 const collection = output.tracks.collection(); 107 + if ((await this.isLeader()) === false) return; 108 + 125 109 console.log("🫠", collection.length); 126 - if ((await this.isLeader()) === false) return; 127 - const { availableTracks } = await this.#proxy.supply(collection); 128 - this.#tracksAvailable.value = availableTracks; 110 + 111 + // Consult input 112 + const groups = await input.groupConsult( 113 + collection.map((t) => t.uri), 114 + ); 115 + 116 + /** @type {Set<string>} */ 117 + const availableUris = new Set(); 118 + 119 + Object.values(groups).forEach((value) => { 120 + if (value.available === false) return; 121 + for (const uri of value.uris) { 122 + availableUris.add(uri); 123 + } 124 + }); 125 + 126 + const availableTracks = collection.filter((t) => { 127 + return t.kind !== "placeholder" && availableUris.has(t.uri); 128 + }); 129 + 130 + // Set pool 131 + search.supply({ tracks: availableTracks }); 132 + 133 + this.#tracksAvailable.set(availableTracks); 129 134 }); 130 135 131 136 // Watch search supply ··· 162 167 163 168 this.#tracksFinal.set(final); 164 169 }); 165 - } 166 - 167 - // WORKERS 168 - 169 - /** 170 - * @override 171 - */ 172 - dependencies() { 173 - if (!this.#input.value) throw new Error("Input element not defined yet"); 174 - if (!this.#search.value) throw new Error("Search element not defined yet"); 175 - 176 - return { 177 - input: this.#input.value, 178 - search: this.#search.value, 179 - }; 180 170 } 181 171 } 182 172
-5
src/components/orchestrator/scoped-tracks/types.d.ts
··· 1 - import type { Track } from "@definitions/types.d.ts"; 2 - 3 - export type Actions = { 4 - supply(tracks: Track[]): Promise<{ availableTracks: Track[] }>; 5 - };
-60
src/components/orchestrator/scoped-tracks/worker.js
··· 1 - import { ostiary, rpc, workerProxy } from "@common/worker.js"; 2 - 3 - /** 4 - * @import {Track} from "@definitions/types.d.ts" 5 - * @import {ActionsWithTunnel, ProxiedActions} from "@common/worker.d.ts" 6 - * @import {InputActions} from "@components/input/types.d.ts" 7 - * @import {Actions as SearchProcessorActions} from "@components/processor/search/types.d.ts" 8 - * @import {Actions} from "./types.d.ts" 9 - */ 10 - 11 - //////////////////////////////////////////// 12 - // ACTIONS 13 - //////////////////////////////////////////// 14 - 15 - /** 16 - * @type {ActionsWithTunnel<Actions>["supply"]} 17 - */ 18 - export async function supply({ data, ports }) { 19 - const cachedTracks = data.filter((t) => t.kind !== "placeholder"); 20 - 21 - /** @type {ProxiedActions<InputActions>} */ 22 - const input = workerProxy(() => ports.input); 23 - 24 - /** @type {ProxiedActions<SearchProcessorActions>} */ 25 - const search = workerProxy(() => ports.search); 26 - 27 - ports.input.start(); 28 - ports.search.start(); 29 - 30 - // Consult input 31 - const groups = await input.groupConsult( 32 - cachedTracks.map((t) => t.uri), 33 - ); 34 - 35 - /** @type {Set<string>} */ 36 - const availableUris = new Set(); 37 - 38 - Object.values(groups).forEach((value) => { 39 - if (value.available === false) return; 40 - for (const uri of value.uris) { 41 - availableUris.add(uri); 42 - } 43 - }); 44 - 45 - const availableTracks = cachedTracks.filter((t) => availableUris.has(t.uri)); 46 - 47 - // Set pool 48 - search.supply({ tracks: availableTracks }); 49 - 50 - // Fin 51 - return { availableTracks }; 52 - } 53 - 54 - //////////////////////////////////////////// 55 - // ⚡️ 56 - //////////////////////////////////////////// 57 - 58 - ostiary((context) => { 59 - rpc(context, { supply }); 60 - });