MCPcopy Create free account
hub / github.com/emwalker/digraph / export_topics

Function export_topics

backend/src/bin/export.rs:343–427  ·  view source on GitHub ↗
(builder: &mut Mutation, pool: &PgPool)

Source from the content-addressed store, hash-verified

341}
342
343async fn export_topics(builder: &mut Mutation, pool: &PgPool) -> Result<()> {
344 log::info!("saving topic blobs");
345
346 let rows = sqlx::query_as::<_, TopicMetadataRow>(
347 r#"select
348 t.name,
349 t.id::varchar,
350 t.synonyms,
351 t.root,
352 t.created_at added,
353 t.repository_id,
354 tr.starts_at timerange_starts,
355 tr.prefix_format timerange_prefix_format
356
357 from topics t
358 left join timeranges tr on tr.id = t.timerange_id"#,
359 )
360 .fetch_all(pool)
361 .await
362 .unwrap();
363
364 for meta in &rows {
365 let repo_id = RepoId::try_from(&meta.repository_id.to_string()).unwrap();
366 let topic_id = sha256_id(&meta.id);
367
368 let parent_topics = sqlx::query_as::<_, ParentTopicRow>(
369 r#"select
370 t.repository_id,
371 tt.parent_id::varchar id,
372 t.name
373
374 from topic_topics tt
375 join topics t on t.id = tt.parent_id
376 left join timeranges tr on tr.id = t.timerange_id
377 where tt.child_id = $1::uuid
378 order by t.name"#,
379 )
380 .bind(&meta.id)
381 .fetch_all(pool)
382 .await
383 .unwrap();
384
385 let children = sqlx::query_as::<_, TopicChildRow>(
386 r#"(
387 select
388 t.created_at added,
389 'Topic' kind,
390 t.repository_id,
391 t.id::varchar,
392 t.name,
393 'url' as url
394
395 from topic_topics tt
396 join topics t on t.id = tt.child_id
397 where tt.parent_id = $1::uuid
398 order by t.name
399 )
400

Callers 1

mainFunction · 0.85

Calls 3

sha256_idFunction · 0.85
persist_topicsFunction · 0.85
fetch_allMethod · 0.80

Tested by

no test coverage detected