MCPcopy
hub / github.com/CapSoftware/Cap / main

Function main

scripts/analytics/populate-test-data.js:192–254  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

190}
191
192async function main() {
193 console.log("Fetching video IDs from database...");
194 const { videoIds, orgMap } = await getVideoIds();
195
196 if (videoIds.length === 0) {
197 console.error("No video IDs found in database");
198 process.exit(1);
199 }
200
201 console.log(`Found ${videoIds.length} video(s)`);
202
203 const distribution = distributeViews(videoIds, MAX_VIEWS);
204 console.log(
205 `Generating ${MAX_VIEWS} test views across ${distribution.length} video(s)...`,
206 );
207
208 const events = [];
209 for (const { videoId, views } of distribution) {
210 const orgId = orgMap.get(videoId) || "";
211 for (let i = 0; i < views; i++) {
212 events.push(generateTestEvent(videoId, orgId, i));
213 }
214 }
215
216 console.log(`Generated ${events.length} events`);
217
218 const auth = resolveTinybirdAuth();
219 const client = createTinybirdClient(auth);
220
221 console.log(`Ingesting events into Tinybird (${auth.host})...`);
222
223 let totalWritten = 0;
224 const chunks = [];
225 for (let i = 0; i < events.length; i += INGEST_CHUNK_SIZE) {
226 chunks.push(events.slice(i, i + INGEST_CHUNK_SIZE));
227 }
228
229 for (let i = 0; i < chunks.length; i++) {
230 const chunk = chunks[i];
231 const ndjson = toNdjson(chunk);
232 await tinybirdIngest({
233 host: client.host,
234 token: client.token,
235 datasource: TB_DATASOURCE,
236 ndjson,
237 });
238 totalWritten += chunk.length;
239 console.log(
240 `Ingested chunk ${i + 1}/${chunks.length} (${chunk.length} events)`,
241 );
242 }
243
244 console.log(
245 `\n✅ Successfully ingested ${totalWritten} events into Tinybird`,
246 );
247 console.log(`\nSummary:`);
248 console.log(` Videos: ${distribution.length}`);
249 console.log(` Total events: ${totalWritten}`);

Callers 1

Calls 7

resolveTinybirdAuthFunction · 0.90
createTinybirdClientFunction · 0.90
getVideoIdsFunction · 0.85
distributeViewsFunction · 0.85
generateTestEventFunction · 0.85
toNdjsonFunction · 0.70
tinybirdIngestFunction · 0.70

Tested by

no test coverage detected