Make euph_trees a temporary database
This commit is contained in:
parent
f272bc6dcb
commit
ad3a67cdc3
3 changed files with 31 additions and 7 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
mod euph;
|
mod euph;
|
||||||
mod migrate;
|
mod migrate;
|
||||||
|
mod prepare;
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{fs, thread};
|
use std::{fs, thread};
|
||||||
|
|
@ -70,6 +71,7 @@ pub fn launch(path: &Path) -> rusqlite::Result<Vault> {
|
||||||
conn.pragma_update(None, "trusted_schema", false)?;
|
conn.pragma_update(None, "trusted_schema", false)?;
|
||||||
|
|
||||||
migrate::migrate(&mut conn)?;
|
migrate::migrate(&mut conn)?;
|
||||||
|
prepare::prepare(&mut conn)?;
|
||||||
|
|
||||||
let (tx, rx) = mpsc::unbounded_channel();
|
let (tx, rx) = mpsc::unbounded_channel();
|
||||||
thread::spawn(move || run(conn, rx));
|
thread::spawn(move || run(conn, rx));
|
||||||
|
|
|
||||||
|
|
@ -60,13 +60,6 @@ fn m1(tx: &mut Transaction) -> rusqlite::Result<()> {
|
||||||
CHECK (start IS NULL OR end IS NOT NULL)
|
CHECK (start IS NULL OR end IS NOT NULL)
|
||||||
) STRICT;
|
) STRICT;
|
||||||
|
|
||||||
CREATE TABLE euph_trees (
|
|
||||||
room TEXT NOT NULL,
|
|
||||||
id INT NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (room, id)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX euph_idx_msgs_room_id_parent
|
CREATE INDEX euph_idx_msgs_room_id_parent
|
||||||
ON euph_msgs (room, id, parent);
|
ON euph_msgs (room, id, parent);
|
||||||
|
|
||||||
|
|
|
||||||
29
src/vault/prepare.rs
Normal file
29
src/vault/prepare.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
use rusqlite::Connection;
|
||||||
|
|
||||||
|
pub fn prepare(conn: &mut Connection) -> rusqlite::Result<()> {
|
||||||
|
conn.execute_batch(
|
||||||
|
"
|
||||||
|
CREATE TEMPORARY TABLE euph_trees (
|
||||||
|
room TEXT NOT NULL,
|
||||||
|
id INT NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (room, id)
|
||||||
|
) STRICT;
|
||||||
|
|
||||||
|
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
|
||||||
|
);
|
||||||
|
",
|
||||||
|
)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue