This commit is contained in:
Yuriy Dupyn 2024-01-28 22:25:38 +01:00
parent 2ba158a0d4
commit 0cac6a0094
3 changed files with 16 additions and 13 deletions

View file

@ -110,8 +110,10 @@ async fn create_token(tokens: &TokenStore) -> anyhow::Result<(i32, i32, ResetCan
let mut tokens = tokens.lock().await;
loop {
let pid_key = random_pid_key();
if !tokens.contains_key(&pid_key) {
tokens.insert(pid_key, token.clone());
use std::collections::hash_map;
if let hash_map::Entry::Vacant(token_entry) = tokens.entry(pid_key) {
token_entry.insert(token.clone());
let (pid, key) = pid_key;
return Ok((pid, key, token));
@ -187,7 +189,7 @@ async fn handle_query<W>(writer: &mut W, state: &SharedDbState, query: String, t
true
}
Response::Selected(schema, columns, mut rows) => {
writer.write_table_header(&schema, &columns).await?;
writer.write_table_header(schema, &columns).await?;
match rows.next() {
Some(row) => {
writer.write_table_row(&row).await?;
@ -223,7 +225,7 @@ async fn handle_query<W>(writer: &mut W, state: &SharedDbState, query: String, t
if need_write {
let state = state.read().await;
state_to_file(&state, &config.get_file_path()).await?;
state_to_file(&state, config.get_file_path()).await?;
}
Ok(())