summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2023-03-13 21:43:50 +0000
committerEllie Huxtable <ellie@elliehuxtable.com>2023-03-13 21:43:50 +0000
commit1cb41cb1ab2dc3f82fa741c860280d1f87ac4872 (patch)
tree5d0d208cd3cf73c9f28e6bebd98078d963611624
parent1f21fa3338370ab6a66a775808eb6f092e405e90 (diff)
Switch to uuidv7 from uuidv4
Why? uuidv4 is totally random. uuidv7 has a time-based prefix, ie, they _sort_. This is important when we start to think about database indices. btree indices have shit performance when the elements are totally random, but good insertion + perf when they are sorted. Plus it's just kinda useful to be able to sort them I don't think it's worth re-ID-ing past data, but at least from hereon out future data will be nice TODO: Update the database schema to use the UUID type, and not just a string.
-rw-r--r--Cargo.lock16
-rw-r--r--atuin-client/src/event.rs6
-rw-r--r--atuin-client/src/history.rs6
-rw-r--r--atuin-client/src/import/resh.rs6
-rw-r--r--atuin-common/Cargo.toml4
-rw-r--r--src/command/mod.rs2
6 files changed, 27 insertions, 13 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c4f0c8c2..17c325ad 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -58,6 +58,15 @@ dependencies = [
]
[[package]]
+name = "atomic"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -150,7 +159,9 @@ name = "atuin-common"
version = "13.0.1"
dependencies = [
"chrono",
+ "hex",
"serde",
+ "sha2",
"uuid",
]
@@ -2540,10 +2551,11 @@ checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9"
[[package]]
name = "uuid"
-version = "1.2.1"
+version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83"
+checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79"
dependencies = [
+ "atomic",
"getrandom",
]
diff --git a/atuin-client/src/event.rs b/atuin-client/src/event.rs
index 4e76c077..07646faa 100644
--- a/atuin-client/src/event.rs
+++ b/atuin-client/src/event.rs
@@ -2,7 +2,7 @@ use chrono::Utc;
use serde::{Deserialize, Serialize};
use crate::history::History;
-use atuin_common::utils::uuid_v4;
+use atuin_common::utils::uuid_v7;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum EventType {
@@ -23,7 +23,7 @@ pub struct Event {
impl Event {
pub fn new_create(history: &History) -> Event {
Event {
- id: uuid_v4(),
+ id: uuid_v7(),
timestamp: history.timestamp,
hostname: history.hostname.clone(),
event_type: EventType::Create,
@@ -36,7 +36,7 @@ impl Event {
let hostname = format!("{}:{}", whoami::hostname(), whoami::username());
Event {
- id: uuid_v4(),
+ id: uuid_v7(),
timestamp: chrono::Utc::now(),
hostname,
event_type: EventType::Create,
diff --git a/atuin-client/src/history.rs b/atuin-client/src/history.rs
index 9a26c95d..4ce988e8 100644
--- a/atuin-client/src/history.rs
+++ b/atuin-client/src/history.rs
@@ -3,7 +3,7 @@ use std::env;
use chrono::Utc;
use serde::{Deserialize, Serialize};
-use atuin_common::utils::uuid_v4;
+use atuin_common::utils::uuid_v7;
// Any new fields MUST be Optional<>!
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, sqlx::FromRow)]
@@ -30,12 +30,12 @@ impl History {
) -> Self {
let session = session
.or_else(|| env::var("ATUIN_SESSION").ok())
- .unwrap_or_else(uuid_v4);
+ .unwrap_or_else(uuid_v7);
let hostname =
hostname.unwrap_or_else(|| format!("{}:{}", whoami::hostname(), whoami::username()));
Self {
- id: uuid_v4(),
+ id: uuid_v7(),
timestamp,
command,
cwd,
diff --git a/atuin-client/src/import/resh.rs b/atuin-client/src/import/resh.rs
index 75487fee..c357fca9 100644
--- a/atuin-client/src/import/resh.rs
+++ b/atuin-client/src/import/resh.rs
@@ -6,7 +6,7 @@ use directories::UserDirs;
use eyre::{eyre, Result};
use serde::Deserialize;
-use atuin_common::utils::uuid_v4;
+use atuin_common::utils::uuid_v7;
use super::{get_histpath, unix_byte_lines, Importer, Loader};
use crate::history::History;
@@ -123,13 +123,13 @@ impl Importer for Resh {
};
h.push(History {
- id: uuid_v4(),
+ id: uuid_v7(),
timestamp,
duration,
exit: entry.exit_code,
command: entry.cmd_line,
cwd: entry.pwd,
- session: uuid_v4(),
+ session: uuid_v7(),
hostname: entry.host,
})
.await?;
diff --git a/atuin-common/Cargo.toml b/atuin-common/Cargo.toml
index 7c407503..34698fe7 100644
--- a/atuin-common/Cargo.toml
+++ b/atuin-common/Cargo.toml
@@ -13,4 +13,6 @@ repository = "https://github.com/ellie/atuin"
[dependencies]
chrono = { version = "0.4", features = ["serde"] }
serde = { version = "1.0.145", features = ["derive"] }
-uuid = { version = "1.2", features = ["v4"] }
+uuid = { version = "1.3", features = ["v7"] }
+sha2 = { version = "0.10" }
+hex = { version = "0.4" }
diff --git a/src/command/mod.rs b/src/command/mod.rs
index 1411bfd2..b79f2ded 100644
--- a/src/command/mod.rs
+++ b/src/command/mod.rs
@@ -60,7 +60,7 @@ impl AtuinCmd {
Ok(())
}
Self::Uuid => {
- println!("{}", atuin_common::utils::uuid_v4());
+ println!("{}", atuin_common::utils::uuid_v7());
Ok(())
}
Self::GenCompletions { shell, out_dir } => {