Skip to content

Commit

Permalink
chore: run sqlite optimize at startup and interval (#621)
Browse files Browse the repository at this point in the history
* chore: run database optimize task on startup and daily

* chore: update sqlx to 0.8

* chore: add test for startup ordering when missing history
  • Loading branch information
dav1do authored Nov 28, 2024
1 parent 3eb821d commit a390db6
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 54 deletions.
86 changes: 40 additions & 46 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ serde_with = "2.1"
sha2 = { version = "0.10", default-features = false }
sha3 = "0.10"
smallvec = "1.10"
sqlx = { version = "0.7", features = ["sqlite", "runtime-tokio", "chrono"] }
sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio", "chrono"] }
ssh-key = { version = "0.5.1", default-features = false }
ssi = { version = "0.7", features = ["ed25519"] }
swagger = { version = "6.1", features = [
Expand Down
19 changes: 19 additions & 0 deletions event-svc/src/event/ordering_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,25 @@ mod test {
assert_eq!(45, event.len());
}

#[test(tokio::test)]
async fn test_undelivered_batch_iterations_ends_when_cant_order() {
let pool = SqlitePool::connect_in_memory().await.unwrap();
let event_access = Arc::new(EventAccess::try_new(pool).await.unwrap());
let mut insertable = get_n_insertable_events(10).await;
let _missing_init = insertable.remove(0);

let _new = event_access.insert_many(insertable.iter()).await.unwrap();
let (_hw, event) = event_access.new_events_since_value(0, 1000).await.unwrap();
assert_eq!(0, event.len());
let res = OrderingState::process_all_undelivered_events(Arc::clone(&event_access), 4, 3)
.await
.unwrap();
assert_eq!(res, 9);

let (_hw, event) = event_access.new_events_since_value(0, 1000).await.unwrap();
assert_eq!(0, event.len());
}

#[test(tokio::test)]
async fn test_undelivered_batch_iterations_ends_when_all_found() {
let pool = SqlitePool::connect_in_memory().await.unwrap();
Expand Down
Loading

0 comments on commit a390db6

Please sign in to comment.