Skip to content

Commit

Permalink
feat: hash query
Browse files Browse the repository at this point in the history
  • Loading branch information
invm committed Oct 9, 2023
1 parent 9ef989f commit 4e67b1f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src-tauri/Cargo.lock

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

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ tokio = { version = "1.32.0", features = ["full"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
sqlparser = "0.38.0"
md-5 = "0.10.6"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
7 changes: 7 additions & 0 deletions src-tauri/src/handlers/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ pub async fn enqueue_query(
match statements {
Ok(statements) => {
if let Some(conn) = conn {
// let mut stmts = vec![];
// // reduce to unique statements
// for stmt in statements.iter() {
// if !stmts.contains(&stmt.to_string()) {
// stmts.push(stmt.to_string());
// }
// }
let async_proc_input_tx = async_state.tasks.lock().await;
for (idx, statement) in statements.iter().enumerate() {
info!("Got statement {:?}", statement.to_string());
Expand Down
9 changes: 5 additions & 4 deletions src-tauri/src/queues/query.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::database::connections::ConnectedConnection;
use crate::utils::crypto::md5_hash;
use anyhow::Result;
use serde::Deserialize;
use serde::Serialize;
use tauri::Manager;
use tokio::sync::mpsc;
use tracing::info;
use uuid::Uuid;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum QueryTaskStatus {
Expand Down Expand Up @@ -33,14 +33,15 @@ pub struct QueryTask {

impl QueryTask {
pub fn new(conn: ConnectedConnection, tab_id: &str, query: &str, query_idx: usize) -> Self {
let id = Uuid::new_v4();
let query_hash = md5_hash(query);
let id = conn.config.id.to_string() + tab_id + &query_hash;
QueryTask {
conn,
id,
tab_id: tab_id.to_string(),
query_idx,
query: query.to_string(),
id: id.to_string(),
status: QueryTaskStatus::Queued,
query_idx,
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/utils/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use md5::{Digest, Md5};
use rand::{distributions::Alphanumeric, Rng};
use simplecrypt::{decrypt, encrypt};
use std::fs;
Expand Down Expand Up @@ -34,6 +35,13 @@ pub fn get_app_key() -> Result<String> {
Ok(key)
}

pub fn md5_hash(data: &str) -> String {
let mut hasher = Md5::new();
hasher.update(data);
let result = hasher.finalize();
format!("{:x}", result)
}

#[cfg(test)]
mod test {
use anyhow::Result;
Expand Down

0 comments on commit 4e67b1f

Please sign in to comment.