Skip to content

Commit

Permalink
Optimize deps
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed Oct 19, 2024
1 parent e41d98d commit e0aace1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 169 deletions.
154 changes: 20 additions & 134 deletions Cargo.lock

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

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,5 @@ actix-governor = { version = "0.6.0", default-features = false }
# https://crates.io/crates/jsonrpc-v2
jsonrpc-v2 = { version = "0.13.0", default-features = false, features = ["actix-web-v4-integration", "easy-errors"] }

# https://docs.rs/crate/dirs
dirs = { version = "5.0.1", default-features = false }

# https://crates.io/crates/base64
base64 = "0.22.1"
17 changes: 3 additions & 14 deletions src/db.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::data_dir_file;
use crate::Result;
use deadpool_sqlite::Config;
use deadpool_sqlite::Hook;
Expand All @@ -7,7 +8,6 @@ use include_dir::include_dir;
use include_dir::Dir;
use rusqlite::Connection;
use std::fmt;
use std::fs::create_dir_all;
use tracing::info;
use tracing::warn;

Expand All @@ -34,7 +34,7 @@ pub fn migrate(db: &mut Connection) -> Result<()> {
}

pub fn pool() -> Result<Pool> {
Ok(Config::new(get_file_path()?)
Ok(Config::new(data_dir_file("btcmap.db")?)
.builder(Runtime::Tokio1)?
.post_create(Hook::Fn(Box::new(|conn, _| {
let conn = conn.lock().unwrap();
Expand All @@ -45,22 +45,11 @@ pub fn pool() -> Result<Pool> {
}

pub fn open_connection() -> Result<Connection> {
let conn = Connection::open(get_file_path()?)?;
let conn = Connection::open(data_dir_file("btcmap.db")?)?;
init_pragmas(&conn);
Ok(conn)
}

pub fn get_file_path() -> Result<PathBuf> {
#[allow(deprecated)]
let data_dir = std::env::home_dir()
.ok_or("Home directory does not exist")?
.join(".local/share/btcmap");
if !data_dir.exists() {
create_dir_all(&data_dir)?;
}
Ok(data_dir.join("btcmap.db"))
}

fn init_pragmas(conn: &Connection) {
conn.pragma_update(None, "journal_mode", "WAL").unwrap();
conn.pragma_update(None, "synchronous", "NORMAL").unwrap();
Expand Down
20 changes: 2 additions & 18 deletions src/log.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::Result;
use crate::{data_dir_file, Result};
use actix_web::HttpRequest;
use dirs::data_dir;
use rusqlite::{named_params, Connection, OptionalExtension, Row};
use std::{fs::create_dir, path::PathBuf};
use time::OffsetDateTime;

#[allow(dead_code)]
Expand Down Expand Up @@ -42,7 +40,7 @@ pub fn log_sync_api_request(
}

pub fn open_conn() -> Result<Connection> {
let conn = Connection::open(db_path()?)?;
let conn = Connection::open(data_dir_file("firewall-v1.db")?)?;
conn.pragma_update(None, "journal_mode", "WAL")?;
conn.pragma_update(None, "synchronous", "NORMAL")?;
conn.execute(
Expand All @@ -63,20 +61,6 @@ pub fn open_conn() -> Result<Connection> {
Ok(conn)
}

pub fn db_path() -> Result<PathBuf> {
let Some(data_dir) = data_dir() else {
Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
"Can't find data directory",
))?
};
let data_dir = data_dir.join("btcmap");
if !data_dir.exists() {
create_dir(&data_dir)?;
}
Ok(data_dir.join("firewall-v1.db"))
}

fn insert_usage_log(
date: &str,
ip: &str,
Expand Down
Loading

0 comments on commit e0aace1

Please sign in to comment.