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: more perf tweaks

+40 -13
+28
src/common/track.js
··· 1 + import * as URI from "fast-uri"; 2 + 3 + /** 4 + * @import {Track} from "@definitions/types.d.ts" 5 + */ 6 + 7 + /** 8 + * @param {string} uri 9 + */ 10 + export function trackURIBase(uri) { 11 + const p = URI.parse(uri); 12 + p.path = undefined; 13 + p.query = undefined; 14 + return URI.serialize(p); 15 + } 16 + 17 + /** 18 + * @param {Track[]} tracks 19 + */ 20 + export function uniqueTrackURIs(tracks) { 21 + const set = new Set(); 22 + 23 + tracks.forEach((t) => { 24 + set.add(trackURIBase(t.uri)); 25 + }); 26 + 27 + return set; 28 + }
+12 -13
src/components/orchestrator/scoped-tracks/element.js
··· 5 5 } from "@common/element.js"; 6 6 import { computed, signal } from "@common/signal.js"; 7 7 import { filterByPlaylist } from "@common/playlist.js"; 8 + import { trackURIBase, uniqueTrackURIs } from "@common/track.js"; 8 9 9 10 /** 10 11 * @import {Track} from "@definitions/types.d.ts" ··· 96 97 if (scope) this.#scope.value = scope; 97 98 98 99 // When defined 100 + await customElements.whenDefined(input.localName); 99 101 await customElements.whenDefined(output.localName); 100 102 if (scope) await customElements.whenDefined(scope.localName); 101 - 102 - let startTime = performance.now(); 103 103 104 104 // Watch tracks collection 105 105 this.effect(async () => { 106 106 const collection = output.tracks.collection(); 107 107 if ((await this.isLeader()) === false) return; 108 108 109 - const endTime = performance.now(); 110 - console.log("🫠", collection.length, endTime - startTime); 109 + /** @type {string[]} */ 110 + const uris = []; 111 + const tracks = collection.filter((t) => { 112 + uris.push(t.uri); 113 + return t.kind !== "placeholder"; 114 + }); 111 115 112 - // Consult input 113 - const groups = await input.groupConsult( 114 - collection.map((t) => t.uri), 115 - ); 116 + // Consult inputs 117 + const groups = collection.length ? await input.groupConsult(uris) : {}; 116 118 117 119 /** @type {Set<string>} */ 118 120 const availableUris = new Set(); ··· 124 126 } 125 127 }); 126 128 127 - const availableTracks = collection.filter((t) => { 128 - return t.kind !== "placeholder" && availableUris.has(t.uri); 129 + const availableTracks = tracks.filter((t) => { 130 + return availableUris.has(t.uri); 129 131 }); 130 132 131 133 // Set pool ··· 162 164 const final = playlistItems?.length 163 165 ? filterByPlaylist(tracks, playlistItems) 164 166 : tracks; 165 - 166 - const endTime = performance.now(); 167 - console.log("🚀", endTime - startTime); 168 167 169 168 this.#tracksFinal.set(final); 170 169 });