-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1468 from cachix/feat-nix-caching
feat: cache nix commands
- Loading branch information
Showing
30 changed files
with
3,058 additions
and
222 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[package] | ||
name = "devenv-eval-cache" | ||
# TODO: switch to workspace version | ||
version = "0.1.0" | ||
edition.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
blake3.workspace = true | ||
futures.workspace = true | ||
lazy_static.workspace = true | ||
miette.workspace = true | ||
regex.workspace = true | ||
serde.workspace = true | ||
serde_json.workspace = true | ||
serde_repr.workspace = true | ||
sqlx.workspace = true | ||
thiserror.workspace = true | ||
tokio.workspace = true | ||
|
||
[dev-dependencies] | ||
tempdir.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
CREATE TABLE IF NOT EXISTS cached_cmd | ||
( | ||
id INTEGER NOT NULL PRIMARY KEY, | ||
raw TEXT NOT NULL, | ||
cmd_hash CHAR(64) NOT NULL UNIQUE, | ||
input_hash CHAR(64) NOT NULL, | ||
output TEXT NOT NULL, | ||
updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_cached_cmd_hash ON cached_cmd(cmd_hash); | ||
|
||
CREATE TABLE IF NOT EXISTS file_path | ||
( | ||
id INTEGER NOT NULL PRIMARY KEY, | ||
path BLOB NOT NULL UNIQUE, | ||
is_directory BOOLEAN NOT NULL, | ||
content_hash CHAR(64) NOT NULL, | ||
modified_at INTEGER NOT NULL, | ||
updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_file_path ON file_path(path); | ||
|
||
CREATE TABLE IF NOT EXISTS cmd_input_path | ||
( | ||
id INTEGER NOT NULL PRIMARY KEY, | ||
cached_cmd_id INTEGER, | ||
file_path_id INTEGER, | ||
UNIQUE(cached_cmd_id, file_path_id), | ||
FOREIGN KEY(cached_cmd_id) | ||
REFERENCES cached_cmd(id) | ||
ON UPDATE CASCADE | ||
ON DELETE CASCADE, | ||
FOREIGN KEY(file_path_id) | ||
REFERENCES file_path(id) | ||
ON UPDATE CASCADE | ||
ON DELETE CASCADE | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_cmd_input_path_cached_cmd_id ON cmd_input_path(cached_cmd_id); | ||
CREATE INDEX IF NOT EXISTS idx_cmd_input_path_file_path_id ON cmd_input_path(file_path_id); | ||
CREATE INDEX IF NOT EXISTS idx_cmd_input_path_composite ON cmd_input_path(cached_cmd_id, file_path_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use std::process::Command; | ||
|
||
use devenv_eval_cache::{command, db}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), command::CommandError> { | ||
let database_url = "sqlite:nix-eval-cache.db"; | ||
let pool = db::setup_db(database_url).await?; | ||
|
||
let mut cmd = Command::new("nix"); | ||
cmd.args(["eval", ".#devenv.processes"]); | ||
|
||
let output = command::CachedCommand::new(&pool).output(&mut cmd).await?; | ||
println!("{}", String::from_utf8_lossy(&output.stdout)); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.