Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/commands/bench/db_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::time::{Duration, Instant};

use crate::db::Db;
use crate::git_utils;
use crate::types::TargetType;

const RESET: &str = "\x1b[0m";
const BOLD: &str = "\x1b[1m";
Expand Down Expand Up @@ -33,9 +34,16 @@ pub fn run() -> Result<()> {
let mut sizes: Vec<usize> = Vec::with_capacity(total);
let mut errors = 0u64;

for (target_type, target_value, key) in &keys {
for (target_type_str, target_value, key) in &keys {
let t0 = Instant::now();
match db.get(target_type, target_value, key) {
let target_type = match TargetType::from_str(target_type_str) {
Ok(tt) => tt,
Err(_) => {
errors += 1;
continue;
}
};
match db.get(&target_type, target_value, key) {
Ok(Some((value, _vtype, _is_git_ref))) => {
let elapsed = t0.elapsed();
let bytes = value.len();
Expand Down
9 changes: 5 additions & 4 deletions src/commands/bench/serialize_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::io::Write;
use std::time::Instant;

use crate::db::Db;
use crate::types::{TargetType, ValueType};

const RESET: &str = "\x1b[0m";
const BOLD: &str = "\x1b[1m";
Expand Down Expand Up @@ -186,15 +187,15 @@ fn do_serialize(repo: &git2::Repository, db: &Db, ref_name: &str) -> Result<()>
/// (which is all we insert in this bench).
fn build_bench_tree(
repo: &git2::Repository,
metadata_entries: &[(String, String, String, String, String, i64, bool)],
metadata_entries: &[(String, String, String, String, ValueType, i64, bool)],
) -> Result<git2::Oid> {
use crate::types::{build_tree_path, Target};
use std::collections::BTreeMap;

let mut files: BTreeMap<String, Vec<u8>> = BTreeMap::new();

for (target_type, target_value, key, value, value_type, _ts, is_git_ref) in metadata_entries {
if value_type != "string" {
if *value_type != ValueType::String {
continue;
}
let target = if target_type == "project" {
Expand Down Expand Up @@ -316,11 +317,11 @@ pub fn run(rounds: usize) -> Result<()> {
let json_value = serde_json::to_string(&value)?;

db.set(
"commit",
&TargetType::Commit,
&sha,
&key,
&json_value,
"string",
&ValueType::String,
"bench@bench",
timestamp_base + i as i64,
)?;
Expand Down
18 changes: 10 additions & 8 deletions src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::{bail, Result};

use crate::context::CommandContext;
use crate::db::Db;
use crate::types::validate_key;
use crate::types::{validate_key, TargetType, ValueType};

const CONFIG_PREFIX: &str = "meta:";

Expand Down Expand Up @@ -44,19 +44,19 @@ fn run_set(ctx: &CommandContext, key: &str, value: &str) -> Result<()> {
let stored_value = serde_json::to_string(value)?;

ctx.db.set(
"project",
&TargetType::Project,
"",
key,
&stored_value,
"string",
&ValueType::String,
&ctx.email,
ctx.timestamp,
)?;
Ok(())
}

fn run_get(db: &Db, key: &str) -> Result<()> {
let result = db.get("project", "", key)?;
let result = db.get(&TargetType::Project, "", key)?;
if let Some((value, _value_type, _is_git_ref)) = result {
let s: String = serde_json::from_str(&value)?;
println!("{}", s);
Expand All @@ -67,10 +67,10 @@ fn run_get(db: &Db, key: &str) -> Result<()> {
fn run_list(db: &Db) -> Result<()> {
// Use "meta" (without trailing colon) as the prefix, since get_all
// appends ":" for LIKE matching: "meta" → matches "meta" OR "meta:%"
let entries = db.get_all("project", "", Some("meta"))?;
let entries = db.get_all(&TargetType::Project, "", Some("meta"))?;
for (key, value, value_type, _is_git_ref) in entries {
let display = match value_type.as_str() {
"string" => {
let display = match value_type {
ValueType::String => {
let s: String = serde_json::from_str(&value)?;
s
}
Expand All @@ -82,7 +82,9 @@ fn run_list(db: &Db) -> Result<()> {
}

fn run_unset(ctx: &CommandContext, key: &str) -> Result<()> {
let removed = ctx.db.rm("project", "", key, &ctx.email, ctx.timestamp)?;
let removed = ctx
.db
.rm(&TargetType::Project, "", key, &ctx.email, ctx.timestamp)?;
if !removed {
eprintln!("key '{}' not found", key);
}
Expand Down
Loading
Loading