This commit is contained in:
Rushmore75 2025-03-21 12:11:05 -06:00
parent b750d88d48
commit 96a3ca092a
2 changed files with 3 additions and 16 deletions

View File

@ -1,21 +1,17 @@
use metrics::counter;
use std::fmt::Debug;
use serde::{Deserialize, Serialize};
use std::{fmt::Debug, sync::LazyLock, time::Instant};
use surrealdb::{
engine::remote::ws::{Client, Ws},
opt::auth::Root,
sql::Thing,
Surreal,
};
use tokio::sync::Mutex;
use tracing::{error, instrument, trace};
use url::Url;
use crate::Config;
static LOCK: LazyLock<Mutex<bool>> = LazyLock::new(|| Mutex::new(true));
const TIME_SPENT_ON_LOCK: &str = "surql_lock_waiting_ms";
const STORE: &str = "surql_store_calls";
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
@ -57,14 +53,6 @@ impl Website {
counter!(STORE).increment(1);
let mut things = Vec::with_capacity(all.len());
// TODO this only allows for one thread to be in the database at a time.
// This is currently required since otherwise we get write errors.
// If the default `crawled` is set to false, we might not need to write any more
// than just the name. `accessed_at` is fun but not needed.
let now = Instant::now();
let lock = LOCK.lock().await;
counter!(TIME_SPENT_ON_LOCK).increment(now.elapsed().as_millis() as u64);
match db
.query(
"INSERT INTO website $array
@ -85,7 +73,6 @@ impl Website {
error!("{:?}", err);
}
}
drop(lock);
things
}
}

View File

@ -1,7 +1,7 @@
use std::{ffi::OsStr, path::PathBuf};
use tokio::fs;
use tracing::{debug, error, info, instrument, trace, warn};
use tracing::{debug, error, instrument, trace, warn};
use url::Url;
#[instrument(skip(data))]
@ -21,7 +21,7 @@ pub async fn store(data: &str, url: &Url) {
(url_path.clone(), "index.html".into())
};
info!("Writing at: {:?} {:?}", basepath, filename);
debug!("Writing at: {:?} {:?}", basepath, filename);
// create the folders
if let Err(err) = fs::create_dir_all(&basepath).await {