A decentralized music tracking and discovery platform built on AT Protocol ๐ŸŽต rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
98
fork

Configure Feed

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

Increase page and batch sizes and reduce delays

Set PAGE_SIZE to 500 and PAGE_DELAY_MS to 0, add YIELD_EVERY_N_PAGES
to yield periodically between pages. Remove the small initial connection
delay and reduce per-page logging frequency to once every 10 pages.
Increase BATCH_SIZE to 200 and lower BATCH_TIMEOUT_MS to 50. Remove
verbose ping/pong log messages.

+9 -14
+7 -12
tap/src/main.ts
··· 6 6 import { omit } from "@es-toolkit/es-toolkit/compat"; 7 7 import type { SelectEvent } from "./schema/event.ts"; 8 8 9 - const PAGE_SIZE = 10; 10 - const PAGE_DELAY_MS = 1; 9 + const PAGE_SIZE = 500; 10 + const PAGE_DELAY_MS = 0; 11 + const YIELD_EVERY_N_PAGES = 5; 11 12 12 13 interface ClientState { 13 14 socket: WebSocket; ··· 68 69 69 70 (async () => { 70 71 try { 71 - // Small delay to ensure connection is fully established 72 - await new Promise((resolve) => setTimeout(resolve, 100)); 73 - 74 72 let page = 0; 75 73 let hasMore = true; 76 74 let totalEvents = 0; ··· 90 88 } 91 89 92 90 while (hasMore && socket.readyState === WebSocket.OPEN) { 93 - logger.info`๐Ÿ“„ Fetching page ${page}...`; 94 - 95 91 const events = await ctx.db 96 92 .select() 97 93 .from(schema.events) ··· 100 96 .limit(PAGE_SIZE) 101 97 .execute(); 102 98 103 - logger.info`๐Ÿ“„ Got ${events.length} events from page ${page}`; 99 + if (page % 10 === 0) { 100 + logger.info`๐Ÿ“„ Fetching page ${page}... (${totalEvents} events sent so far)`; 101 + } 104 102 105 103 for (const evt of events) { 106 104 if (socket.readyState === WebSocket.OPEN) { ··· 119 117 hasMore = events.length === PAGE_SIZE; 120 118 page++; 121 119 122 - // Yield to event loop between pages 123 - if (hasMore) { 120 + if (hasMore && page % YIELD_EVERY_N_PAGES === 0) { 124 121 await new Promise((resolve) => setTimeout(resolve, PAGE_DELAY_MS)); 125 122 } 126 123 } ··· 173 170 }); 174 171 175 172 socket.addEventListener("message", (event) => { 176 - logger.info`๐Ÿ“จ Received message: ${event.data}`; 177 173 if (event.data === "ping") { 178 174 socket.send("pong"); 179 - logger.info`๐Ÿ“ค Sent pong`; 180 175 } 181 176 }); 182 177
+2 -2
tap/src/tap.ts
··· 8 8 9 9 export const TAP_WS_URL = Deno.env.get("TAP_URL") || "http://localhost:2480"; 10 10 11 - const BATCH_SIZE = 50; 12 - const BATCH_TIMEOUT_MS = 100; 11 + const BATCH_SIZE = 200; 12 + const BATCH_TIMEOUT_MS = 50; 13 13 14 14 export default function connectToTap() { 15 15 const tap = new Tap(TAP_WS_URL);