Skip to content
Snippets Groups Projects
Commit fcbcd27a authored by Stephen D's avatar Stephen D
Browse files

improve edge insertion speed, I hope

parent cbf2f7c4
No related tags found
No related merge requests found
...@@ -238,7 +238,27 @@ async fn get_edges( ...@@ -238,7 +238,27 @@ async fn get_edges(
}) })
.unzip(); .unzip();
query!("INSERT INTO edges(from_id, to_id) SELECT UNNEST($1::INT[]), UNNEST($2::INT[]) ON CONFLICT DO NOTHING", &from_ids, &to_ids).execute(&p).await?; query!(
r#"
WITH unique_edges AS (
SELECT UNNEST($1::INT[]) AS from_id, UNNEST($2::INT[]) AS to_id
)
INSERT INTO edges(from_id, to_id)
SELECT ue.from_id, ue.to_id
FROM unique_edges ue
WHERE NOT EXISTS (
SELECT 1
FROM edges e
WHERE e.from_id = ue.from_id
AND e.to_id = ue.to_id
)
ON CONFLICT DO NOTHING
"#,
&from_ids,
&to_ids
)
.execute(&p)
.await?;
statsd.count("edges.inserts", from_ids.len() as f64, &None); statsd.count("edges.inserts", from_ids.len() as f64, &None);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment