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 reduce back and forth worker

+12 -32
+1 -1
src/components/configurator/input/element.js
··· 1 - import { DiffuseElement, whenElementsDefined } from "@common/element.js"; 1 + import { DiffuseElement } from "@common/element.js"; 2 2 3 3 /** 4 4 * @import {ProxiedActions, Tunnel} from "@common/worker.d.ts"
+9 -2
src/components/orchestrator/scoped-tracks/element.js
··· 4 4 queryOptional, 5 5 } from "@common/element.js"; 6 6 import { computed, signal } from "@common/signal.js"; 7 + import { filterByPlaylist } from "@common/playlist.js"; 7 8 8 9 /** 9 10 * @import {Track} from "@definitions/types.d.ts" ··· 116 117 await customElements.whenDefined(output.localName); 117 118 if (scope) await customElements.whenDefined(scope.localName); 118 119 120 + const startTime = performance.now(); 121 + 119 122 // Watch tracks collection 120 123 this.effect(async () => { 121 124 const collection = output.tracks.collection(); 125 + console.log("🫠", collection.length); 122 126 if ((await this.isLeader()) === false) return; 123 127 const { availableTracks } = await this.#proxy.supply(collection); 124 128 this.#tracksAvailable.value = availableTracks; ··· 133 137 if ((await this.isLeader()) === false) return; 134 138 135 139 if (searchTerm?.length) { 136 - const searchResults = await this.#proxy.searchTracks({ 140 + const searchResults = await search.search({ 137 141 term: searchTerm, 138 142 }); 139 143 this.#tracksSearch.set(searchResults); ··· 150 154 if ((await this.isLeader()) === false) return; 151 155 152 156 const final = playlistItems?.length 153 - ? await this.#proxy.filterByPlaylist({ tracks, playlistItems }) 157 + ? filterByPlaylist(tracks, playlistItems) 154 158 : tracks; 159 + 160 + const endTime = performance.now(); 161 + console.log("🚀", endTime - startTime); 155 162 156 163 this.#tracksFinal.set(final); 157 164 });
+1 -8
src/components/orchestrator/scoped-tracks/types.d.ts
··· 1 - import type { SearchParams } from "@orama/orama"; 2 - 3 - import type { PlaylistItem, Track } from "@definitions/types.d.ts"; 4 - import type { Schema } from "@components/processor/search/types.d.ts"; 1 + import type { Track } from "@definitions/types.d.ts"; 5 2 6 3 export type Actions = { 7 - filterByPlaylist( 8 - args: { tracks: Track[]; playlistItems: PlaylistItem[] }, 9 - ): Promise<Track[]>; 10 - searchTracks(params: SearchParams<Schema>): Promise<Track[]>; 11 4 supply(tracks: Track[]): Promise<{ availableTracks: Track[] }>; 12 5 };
+1 -21
src/components/orchestrator/scoped-tracks/worker.js
··· 48 48 return { availableTracks }; 49 49 } 50 50 51 - /** 52 - * @type {ActionsWithTunnel<Actions>["searchTracks"]} 53 - */ 54 - export async function searchTracks({ data, ports }) { 55 - /** @type {ProxiedActions<SearchProcessorActions>} */ 56 - const search = workerProxy(() => { 57 - ports.search.start(); 58 - return ports.search; 59 - }); 60 - 61 - return await search.search(data); 62 - } 63 - 64 - /** 65 - * @type {ActionsWithTunnel<Actions>["filterByPlaylist"]} 66 - */ 67 - export async function filterByPlaylist({ data }) { 68 - return filterByPlaylistFn(data.tracks, data.playlistItems); 69 - } 70 - 71 51 //////////////////////////////////////////// 72 52 // ⚡️ 73 53 //////////////////////////////////////////// 74 54 75 55 ostiary((context) => { 76 - rpc(context, { filterByPlaylist, searchTracks, supply }); 56 + rpc(context, { supply }); 77 57 });