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

Function persist_topics

backend/src/bin/export.rs:274–341  ·  view source on GitHub ↗

1. Don't place paths for items in private repos under /wiki/

(
    mutation: &mut Mutation,
    repo_topic_repo_id: RepoId,
    topic_id: &ExternalId,
    meta: &TopicMetadataRow,
    parent_topics: &Vec<ParentTopicRow>,
    children: &Vec<TopicChildRow>,
)

Source from the content-addressed store, hash-verified

272
273// 1. Don't place paths for items in private repos under /wiki/
274fn persist_topics(
275 mutation: &mut Mutation,
276 repo_topic_repo_id: RepoId,
277 topic_id: &ExternalId,
278 meta: &TopicMetadataRow,
279 parent_topics: &Vec<ParentTopicRow>,
280 children: &Vec<TopicChildRow>,
281) -> Result<()> {
282 let deserialized =
283 serde_json::from_value::<Vec<HashMap<String, String>>>(meta.synonyms.clone())?;
284
285 let mut synonyms: Vec<SynonymRow> = vec![];
286 for s in &deserialized {
287 synonyms.push(SynonymRow {
288 added: meta.added,
289 locale: s.get("Locale").unwrap_or(&String::from("en")).to_string(),
290 name: s.get("Name").unwrap_or(&meta.name).to_string(),
291 });
292 }
293
294 let timerange = match (&meta.timerange_starts, &meta.timerange_prefix_format) {
295 (Some(starts), Some(prefix_format)) => Some(Timerange {
296 starts: Geotime::from(starts).into(),
297 prefix_format: TimerangePrefixFormat::from(prefix_format.as_str()),
298 }),
299 _ => None,
300 };
301
302 let repo_topic = RepoTopic {
303 api_version: API_VERSION.to_string(),
304 metadata: RepoTopicMetadata {
305 added: meta.added,
306 id: topic_id.to_owned(),
307 details: Some(RepoTopicDetails {
308 root: meta.root,
309 synonyms: synonyms.iter().map(Synonym::from).collect(),
310 timerange,
311 }),
312 },
313 parent_topics: BTreeSet::new(),
314 children: BTreeSet::new(),
315 };
316
317 let mut topics = RepoTopics::new(repo_topic_repo_id, repo_topic);
318
319 for parent in parent_topics {
320 let parent_repo_id = RepoId::try_from(&parent.repository_id).unwrap();
321 let repo_id = prefer_private_repo(repo_topic_repo_id, parent_repo_id);
322 let topic = topics.get_mut(repo_id);
323 topic.parent_topics.insert(parent.try_into()?);
324 }
325
326 for child in children {
327 let parent_repo_id = RepoId::try_from(&child.repository_id).unwrap();
328 let repo_id = prefer_private_repo(repo_topic_repo_id, parent_repo_id);
329 let topic = topics.get_mut(repo_id);
330 topic.children.insert(child.try_into()?);
331 }

Callers 1

export_topicsFunction · 0.85

Calls 8

prefer_private_repoFunction · 0.85
persist_topicFunction · 0.85
as_strMethod · 0.80
get_mutMethod · 0.80
insertMethod · 0.80
getMethod · 0.45
iterMethod · 0.45
try_intoMethod · 0.45

Tested by

no test coverage detected