Skip to content

Commit cc84ddb

Browse files
chore: update, remove cache
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent 3afd59f commit cc84ddb

13 files changed

Lines changed: 103 additions & 268 deletions

File tree

Cargo.lock

Lines changed: 47 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ hex={version="0.4"}
2727
bs58="0.5"
2828
serde={version="1.0", features=["derive"]}
2929
serde_json={version="1.0"}
30-
md-5={version="0.10"}
30+
md-5={version="0.11.0-rc.5"}
3131
async-compression={version="0.4", default-features=false, features=["gzip", "tokio"]}
3232
tokio-tar={package="astral-tokio-tar", version="0.5"}
3333
blake3={version="1.8"}
@@ -41,8 +41,7 @@ zstd={version="0.13", default-features=false}
4141
# general
4242
argh={version="0.1", default-features=false, features=["help"]}
4343
anyhow={version="1.0"}
44-
rand_core={version="0.10"}
45-
rand={version="0.9", default-features=false, features=["std", "thread_rng"]}
44+
rand={version="0.10.0-rc.9", default-features=false, features=["std", "thread_rng"]}
4645
chrono={version="0.4", default-features=false, features=["std", "now", "serde"]}
4746
figment={version="0.10", features=["toml", "env"]}
4847
tracing={version="0.1", default-features=false, features=["std"]}

src/app/core.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pub mod events;
33
pub mod onboarding;
44
pub mod projects;
55
pub mod reports;
6-
mod reports_cached;
76
pub mod sessions;
87
pub mod users;
98

src/app/core/events.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33
use anyhow::{Result, bail};
44
use arc_swap::ArcSwap;
55
use chrono::{DateTime, Utc};
6-
use password_hash::try_generate_salt;
6+
use rand::distr::{SampleString, StandardUniform};
77
use std::sync::mpsc::Receiver;
88

99
use crate::app::models::{Event, event_params};
@@ -13,12 +13,12 @@ use crate::app::{DuckDBPool, EVENT_BATCH_INTERVAL, SqlitePool};
1313
pub struct LiwanEvents {
1414
duckdb: DuckDBPool,
1515
sqlite: SqlitePool,
16-
daily_salt: Arc<ArcSwap<([u8; 16], DateTime<Utc>)>>,
16+
daily_salt: Arc<ArcSwap<(String, DateTime<Utc>)>>,
1717
}
1818

1919
impl LiwanEvents {
2020
pub fn try_new(duckdb: DuckDBPool, sqlite: SqlitePool) -> Result<Self> {
21-
let daily_salt: ([u8; 16], DateTime<Utc>) = {
21+
let daily_salt: (String, DateTime<Utc>) = {
2222
tracing::debug!("Loading daily salt");
2323
sqlite.get()?.query_row("select salt, updated_at from salts where id = 1", [], |row| {
2424
Ok((row.get(0)?, row.get(1)?))
@@ -28,13 +28,13 @@ impl LiwanEvents {
2828
}
2929

3030
/// Get the daily salt, generating a new one if the current one is older than 24 hours
31-
pub fn get_salt(&self) -> Result<[u8; 16]> {
31+
pub fn get_salt(&self) -> Result<String> {
3232
let (salt, updated_at) = &**self.daily_salt.load();
3333

3434
// if the salt is older than 24 hours, replace it with a new one (utils::generate_salt)
3535
if (Utc::now() - updated_at) > chrono::Duration::hours(24) {
3636
tracing::debug!("Daily salt expired, generating a new one");
37-
let new_salt = try_generate_salt()?;
37+
let new_salt = StandardUniform.sample_string(&mut rand::rng(), 16);
3838
let now = Utc::now();
3939
let conn = self.sqlite.get()?;
4040
conn.execute("update salts set salt = ?, updated_at = ? where id = 1", rusqlite::params![&new_salt, now])?;

src/app/core/geoip.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(dead_code)]
22

3-
use std::io::{self};
3+
use std::io::{self, Read};
44
use std::net::IpAddr;
55
use std::path::{Path, PathBuf};
66
use std::sync::Arc;
@@ -233,8 +233,17 @@ fn file_md5(path: &Path) -> Result<String> {
233233
let file = std::fs::File::open(path)?;
234234
let mut reader = std::io::BufReader::new(file);
235235
let mut hasher = md5::Md5::new();
236-
std::io::copy(&mut reader, &mut hasher)?;
237-
Ok(format!("{:x}", hasher.finalize()))
236+
237+
let mut buffer = [0u8; 8192];
238+
loop {
239+
let n = reader.read(&mut buffer)?;
240+
if n == 0 {
241+
break;
242+
}
243+
hasher.update(&buffer[..n]);
244+
}
245+
246+
Ok(hex::encode(hasher.finalize()))
238247
}
239248

240249
async fn download_maxmind_db(edition: &str, account_id: &str, license_key: &str) -> Result<PathBuf> {

src/app/core/reports.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use duckdb::params_from_iter;
99
use schemars::JsonSchema;
1010
use serde::{Deserialize, Serialize};
1111

12-
pub use super::reports_cached::*;
13-
1412
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, Hash, PartialEq, Eq)]
1513
pub struct DateRange {
1614
pub start: DateTime<Utc>,

0 commit comments

Comments
 (0)