Update vault

This commit is contained in:
Joscha 2023-04-19 23:24:35 +02:00
parent 164c02243d
commit 318f7e2a73
5 changed files with 112 additions and 77 deletions

30
Cargo.lock generated
View file

@ -103,6 +103,12 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c70beb79cbb5ce9c4f8e20849978f34225931f665bb49efa6982875a4d5facb3"
[[package]] [[package]]
name = "block-buffer" name = "block-buffer"
version = "0.10.4" version = "0.10.4"
@ -171,7 +177,7 @@ checksum = "223163f58c9a40c3b0a43e1c4b50a9ce09f007ea2cb1ec258a687945b4b7929f"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
"bitflags", "bitflags 1.3.2",
"clap_lex", "clap_lex",
"strsim", "strsim",
] ]
@ -281,7 +287,7 @@ version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13" checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13"
dependencies = [ dependencies = [
"bitflags", "bitflags 1.3.2",
"crossterm_winapi", "crossterm_winapi",
"libc", "libc",
"mio", "mio",
@ -617,9 +623,9 @@ checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5"
[[package]] [[package]]
name = "libsqlite3-sys" name = "libsqlite3-sys"
version = "0.25.2" version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29f835d03d717946d28b1d1ed632eb6f0e24a299388ee623d0c23118d3e8a7fa" checksum = "afc22eff61b133b115c6e8c74e818c628d6d5e7a502afea6f64dee076dd94326"
dependencies = [ dependencies = [
"cc", "cc",
"pkg-config", "pkg-config",
@ -822,7 +828,7 @@ version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [ dependencies = [
"bitflags", "bitflags 1.3.2",
] ]
[[package]] [[package]]
@ -831,7 +837,7 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
dependencies = [ dependencies = [
"bitflags", "bitflags 1.3.2",
] ]
[[package]] [[package]]
@ -879,11 +885,11 @@ dependencies = [
[[package]] [[package]]
name = "rusqlite" name = "rusqlite"
version = "0.28.0" version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01e213bc3ecb39ac32e81e51ebe31fd888a940515173e3a18a35f8c6e896422a" checksum = "549b9d036d571d42e6e85d1c1425e2ac83491075078ca9a15be021c56b1641f2"
dependencies = [ dependencies = [
"bitflags", "bitflags 2.1.0",
"fallible-iterator", "fallible-iterator",
"fallible-streaming-iterator", "fallible-streaming-iterator",
"hashlink", "hashlink",
@ -898,7 +904,7 @@ version = "0.37.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85597d61f83914ddeba6a47b3b8ffe7365107221c2e557ed94426489fefb5f77" checksum = "85597d61f83914ddeba6a47b3b8ffe7365107221c2e557ed94426489fefb5f77"
dependencies = [ dependencies = [
"bitflags", "bitflags 1.3.2",
"errno", "errno",
"io-lifetimes", "io-lifetimes",
"libc", "libc",
@ -976,7 +982,7 @@ version = "2.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254"
dependencies = [ dependencies = [
"bitflags", "bitflags 1.3.2",
"core-foundation", "core-foundation",
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
@ -1424,7 +1430,7 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]] [[package]]
name = "vault" name = "vault"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/Garmelon/vault.git?tag=v0.1.0#028c72cac4e84bfbbf9fb03b15acb59989a31df9" source = "git+https://github.com/Garmelon/vault.git?rev=b4cf23b7279770226725c895e482c8eda88c43a7#b4cf23b7279770226725c895e482c8eda88c43a7"
dependencies = [ dependencies = [
"rusqlite", "rusqlite",
"tokio", "tokio",

View file

@ -16,7 +16,7 @@ log = { version = "0.4.17", features = ["std"] }
once_cell = "1.17.1" once_cell = "1.17.1"
open = "4.0.1" open = "4.0.1"
parking_lot = "0.12.1" parking_lot = "0.12.1"
rusqlite = { version = "0.28.0", features = ["bundled", "time"] } rusqlite = { version = "0.29.0", features = ["bundled", "time"] }
serde = { version = "1.0.159", features = ["derive"] } serde = { version = "1.0.159", features = ["derive"] }
serde_json = "1.0.95" serde_json = "1.0.95"
thiserror = "1.0.40" thiserror = "1.0.40"
@ -50,7 +50,7 @@ rev = "f414db40d526295c74cbcae6c3d194088da8f1d9"
[dependencies.vault] [dependencies.vault]
git = "https://github.com/Garmelon/vault.git" git = "https://github.com/Garmelon/vault.git"
tag = "v0.1.0" rev = "b4cf23b7279770226725c895e482c8eda88c43a7"
features = ["tokio"] features = ["tokio"]
# [patch."https://github.com/Garmelon/vault.git"] # [patch."https://github.com/Garmelon/vault.git"]

View file

@ -36,7 +36,7 @@ const EVENT_PROCESSING_TIME: Duration = Duration::from_millis(1000 / 15); // 15
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum UiError { pub enum UiError {
#[error("{0}")] #[error("{0}")]
Vault(#[from] vault::tokio::Error), Vault(#[from] vault::tokio::Error<rusqlite::Error>),
#[error("{0}")] #[error("{0}")]
Io(#[from] io::Error), Io(#[from] io::Error),
} }

View file

@ -20,9 +20,10 @@ pub struct Vault {
struct GcAction; struct GcAction;
impl Action for GcAction { impl Action for GcAction {
type Result = (); type Output = ();
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
conn.execute_batch("ANALYZE; VACUUM;") conn.execute_batch("ANALYZE; VACUUM;")
} }
} }
@ -36,7 +37,7 @@ impl Vault {
self.tokio_vault.stop().await; self.tokio_vault.stop().await;
} }
pub async fn gc(&self) -> vault::tokio::Result<()> { pub async fn gc(&self) -> Result<(), vault::tokio::Error<rusqlite::Error>> {
self.tokio_vault.execute(GcAction).await self.tokio_vault.execute(GcAction).await
} }

View file

@ -88,7 +88,7 @@ macro_rules! euph_vault_actions {
impl EuphVault { impl EuphVault {
$( $(
pub async fn $fn(&self, $( $arg: $arg_ty, )* ) -> vault::tokio::Result<$res> { pub async fn $fn(&self, $( $arg: $arg_ty, )* ) -> Result<$res, vault::tokio::Error<rusqlite::Error>> {
self.vault.tokio_vault.execute($struct { $( $arg, )* }).await self.vault.tokio_vault.execute($struct { $( $arg, )* }).await
} }
)* )*
@ -103,9 +103,10 @@ euph_vault_actions! {
} }
impl Action for GetCookies { impl Action for GetCookies {
type Result = CookieJar; type Output = CookieJar;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let cookies = conn let cookies = conn
.prepare( .prepare(
" "
@ -128,9 +129,10 @@ impl Action for GetCookies {
} }
impl Action for SetCookies { impl Action for SetCookies {
type Result = (); type Output = ();
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let tx = conn.transaction()?; let tx = conn.transaction()?;
// Since euphoria sets all cookies on every response, we can just delete // Since euphoria sets all cookies on every response, we can just delete
@ -154,9 +156,10 @@ impl Action for SetCookies {
} }
impl Action for GetRooms { impl Action for GetRooms {
type Result = Vec<String>; type Output = Vec<String>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
conn.prepare( conn.prepare(
" "
SELECT room SELECT room
@ -201,7 +204,7 @@ macro_rules! euph_room_vault_actions {
impl EuphRoomVault { impl EuphRoomVault {
$( $(
pub async fn $fn(&self, $( $arg: $arg_ty, )* ) -> vault::tokio::Result<$res> { pub async fn $fn(&self, $( $arg: $arg_ty, )* ) -> Result<$res, vault::tokio::Error<rusqlite::Error>> {
self.vault.vault.tokio_vault.execute($struct { self.vault.vault.tokio_vault.execute($struct {
room: self.room.clone(), room: self.room.clone(),
$( $arg, )* $( $arg, )*
@ -244,9 +247,10 @@ euph_room_vault_actions! {
} }
impl Action for Join { impl Action for Join {
type Result = (); type Output = ();
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
conn.execute( conn.execute(
" "
INSERT INTO euph_rooms (room, first_joined, last_joined) INSERT INTO euph_rooms (room, first_joined, last_joined)
@ -261,9 +265,10 @@ impl Action for Join {
} }
impl Action for Delete { impl Action for Delete {
type Result = (); type Output = ();
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
conn.execute( conn.execute(
" "
DELETE FROM euph_rooms DELETE FROM euph_rooms
@ -431,9 +436,10 @@ fn add_span(
} }
impl Action for AddMsg { impl Action for AddMsg {
type Result = (); type Output = ();
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let tx = conn.transaction()?; let tx = conn.transaction()?;
let end = self.msg.id; let end = self.msg.id;
@ -446,9 +452,10 @@ impl Action for AddMsg {
} }
impl Action for AddMsgs { impl Action for AddMsgs {
type Result = (); type Output = ();
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let tx = conn.transaction()?; let tx = conn.transaction()?;
if self.msgs.is_empty() { if self.msgs.is_empty() {
@ -469,9 +476,10 @@ impl Action for AddMsgs {
} }
impl Action for GetLastSpan { impl Action for GetLastSpan {
type Result = Option<(Option<MessageId>, Option<MessageId>)>; type Output = Option<(Option<MessageId>, Option<MessageId>)>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let span = conn let span = conn
.prepare( .prepare(
" "
@ -494,9 +502,10 @@ impl Action for GetLastSpan {
} }
impl Action for GetPath { impl Action for GetPath {
type Result = Path<MessageId>; type Output = Path<MessageId>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let path = conn let path = conn
.prepare( .prepare(
" "
@ -523,9 +532,10 @@ impl Action for GetPath {
} }
impl Action for GetMsg { impl Action for GetMsg {
type Result = Option<SmallMessage>; type Output = Option<SmallMessage>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let msg = conn let msg = conn
.query_row( .query_row(
" "
@ -552,9 +562,10 @@ impl Action for GetMsg {
} }
impl Action for GetFullMsg { impl Action for GetFullMsg {
type Result = Option<Message>; type Output = Option<Message>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let mut query = conn.prepare( let mut query = conn.prepare(
" "
SELECT SELECT
@ -597,9 +608,10 @@ impl Action for GetFullMsg {
} }
impl Action for GetTree { impl Action for GetTree {
type Result = Tree<SmallMessage>; type Output = Tree<SmallMessage>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let msgs = conn let msgs = conn
.prepare( .prepare(
" "
@ -635,9 +647,10 @@ impl Action for GetTree {
} }
impl Action for GetFirstRootId { impl Action for GetFirstRootId {
type Result = Option<MessageId>; type Output = Option<MessageId>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let root_id = conn let root_id = conn
.prepare( .prepare(
" "
@ -657,9 +670,10 @@ impl Action for GetFirstRootId {
} }
impl Action for GetLastRootId { impl Action for GetLastRootId {
type Result = Option<MessageId>; type Output = Option<MessageId>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let root_id = conn let root_id = conn
.prepare( .prepare(
" "
@ -679,9 +693,10 @@ impl Action for GetLastRootId {
} }
impl Action for GetPrevRootId { impl Action for GetPrevRootId {
type Result = Option<MessageId>; type Output = Option<MessageId>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let root_id = conn let root_id = conn
.prepare( .prepare(
" "
@ -702,9 +717,10 @@ impl Action for GetPrevRootId {
} }
impl Action for GetNextRootId { impl Action for GetNextRootId {
type Result = Option<MessageId>; type Output = Option<MessageId>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let root_id = conn let root_id = conn
.prepare( .prepare(
" "
@ -725,9 +741,10 @@ impl Action for GetNextRootId {
} }
impl Action for GetOldestMsgId { impl Action for GetOldestMsgId {
type Result = Option<MessageId>; type Output = Option<MessageId>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let msg_id = conn let msg_id = conn
.prepare( .prepare(
" "
@ -747,9 +764,10 @@ impl Action for GetOldestMsgId {
} }
impl Action for GetNewestMsgId { impl Action for GetNewestMsgId {
type Result = Option<MessageId>; type Output = Option<MessageId>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let msg_id = conn let msg_id = conn
.prepare( .prepare(
" "
@ -769,9 +787,10 @@ impl Action for GetNewestMsgId {
} }
impl Action for GetOlderMsgId { impl Action for GetOlderMsgId {
type Result = Option<MessageId>; type Output = Option<MessageId>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let msg_id = conn let msg_id = conn
.prepare( .prepare(
" "
@ -791,9 +810,10 @@ impl Action for GetOlderMsgId {
} }
} }
impl Action for GetNewerMsgId { impl Action for GetNewerMsgId {
type Result = Option<MessageId>; type Output = Option<MessageId>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let msg_id = conn let msg_id = conn
.prepare( .prepare(
" "
@ -814,9 +834,10 @@ impl Action for GetNewerMsgId {
} }
impl Action for GetOldestUnseenMsgId { impl Action for GetOldestUnseenMsgId {
type Result = Option<MessageId>; type Output = Option<MessageId>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let msg_id = conn let msg_id = conn
.prepare( .prepare(
" "
@ -837,9 +858,10 @@ impl Action for GetOldestUnseenMsgId {
} }
impl Action for GetNewestUnseenMsgId { impl Action for GetNewestUnseenMsgId {
type Result = Option<MessageId>; type Output = Option<MessageId>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let msg_id = conn let msg_id = conn
.prepare( .prepare(
" "
@ -860,9 +882,10 @@ impl Action for GetNewestUnseenMsgId {
} }
impl Action for GetOlderUnseenMsgId { impl Action for GetOlderUnseenMsgId {
type Result = Option<MessageId>; type Output = Option<MessageId>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let msg_id = conn let msg_id = conn
.prepare( .prepare(
" "
@ -884,9 +907,10 @@ impl Action for GetOlderUnseenMsgId {
} }
impl Action for GetNewerUnseenMsgId { impl Action for GetNewerUnseenMsgId {
type Result = Option<MessageId>; type Output = Option<MessageId>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let msg_id = conn let msg_id = conn
.prepare( .prepare(
" "
@ -908,9 +932,10 @@ impl Action for GetNewerUnseenMsgId {
} }
impl Action for GetUnseenMsgsCount { impl Action for GetUnseenMsgsCount {
type Result = usize; type Output = usize;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
let amount = conn let amount = conn
.prepare( .prepare(
" "
@ -927,9 +952,10 @@ impl Action for GetUnseenMsgsCount {
} }
impl Action for SetSeen { impl Action for SetSeen {
type Result = (); type Output = ();
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
conn.execute( conn.execute(
" "
UPDATE euph_msgs UPDATE euph_msgs
@ -944,9 +970,10 @@ impl Action for SetSeen {
} }
impl Action for SetOlderSeen { impl Action for SetOlderSeen {
type Result = (); type Output = ();
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
conn.execute( conn.execute(
" "
UPDATE euph_msgs UPDATE euph_msgs
@ -962,9 +989,10 @@ impl Action for SetOlderSeen {
} }
impl Action for GetChunkAfter { impl Action for GetChunkAfter {
type Result = Vec<Message>; type Output = Vec<Message>;
type Error = rusqlite::Error;
fn run(self, conn: &mut Connection) -> rusqlite::Result<Self::Result> { fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
fn row2msg(row: &Row<'_>) -> rusqlite::Result<Message> { fn row2msg(row: &Row<'_>) -> rusqlite::Result<Message> {
Ok(Message { Ok(Message {
id: MessageId(row.get::<_, WSnowflake>(0)?.0), id: MessageId(row.get::<_, WSnowflake>(0)?.0),
@ -1023,7 +1051,7 @@ impl Action for GetChunkAfter {
#[async_trait] #[async_trait]
impl MsgStore<SmallMessage> for EuphRoomVault { impl MsgStore<SmallMessage> for EuphRoomVault {
type Error = vault::tokio::Error; type Error = vault::tokio::Error<rusqlite::Error>;
async fn path(&self, id: &MessageId) -> Result<Path<MessageId>, Self::Error> { async fn path(&self, id: &MessageId) -> Result<Path<MessageId>, Self::Error> {
self.path(*id).await self.path(*id).await