Make euph_trees a table instead of a view

This commit is contained in:
Joscha 2022-06-24 19:19:38 +02:00
parent b30adaf17c
commit 6facbd5c96
2 changed files with 27 additions and 13 deletions

View file

@ -301,6 +301,28 @@ impl EuphRequest {
])?;
}
// Update euph_trees
tx.execute_batch(
"
DELETE FROM euph_trees;
INSERT INTO euph_trees (room, id)
SELECT room, id
FROM euph_msgs
WHERE parent IS NULL
UNION
SELECT room, parent
FROM euph_msgs
WHERE parent IS NOT NULL
AND NOT EXISTS(
SELECT *
FROM euph_msgs AS parents
WHERE parents.room = euph_msgs.room
AND parents.id = euph_msgs.parent
);
",
)?;
Ok(())
}