use std::sync::{LazyLock, Mutex};
use schnellru::{ByLength, LruMap};
use autonomi::client::files::archive_public::ArchiveAddress;
use crate::files::directory::Tree;
use crate::history::HistoryAddress;
use crate::web::name::DwebHost;
const DWEB_NAMES_CAPACITY: u32 = 1000; const VERSIONS_CAPACITY: u32 = 1000;
pub static DIRECTORY_VERSIONS_WITH_NAME: LazyLock<Mutex<LruMap<String, DirectoryVersionWithName>>> =
LazyLock::new(|| {
Mutex::<LruMap<String, DirectoryVersionWithName>>::new(LruMap::<
String,
DirectoryVersionWithName,
>::new(ByLength::new(
VERSIONS_CAPACITY,
)))
});
pub static HISTORY_NAMES: LazyLock<Mutex<LruMap<String, HistoryAddress>>> = LazyLock::new(|| {
Mutex::<LruMap<String, HistoryAddress>>::new(LruMap::<String, HistoryAddress>::new(
ByLength::new(DWEB_NAMES_CAPACITY),
))
});
#[derive(Clone)]
pub struct DirectoryVersionWithName {
dweb_host_string: String,
pub history_address: HistoryAddress,
version: Option<u64>,
pub archive_address: ArchiveAddress,
pub directory_tree: Option<Tree>,
#[cfg(feature = "fixed-dweb-hosts")]
is_fixed_webname: bool,
}
impl DirectoryVersionWithName {
pub fn new(
web_name: &DwebHost,
history_address: HistoryAddress,
archive_address: ArchiveAddress,
directory_tree: Option<Tree>,
) -> DirectoryVersionWithName {
DirectoryVersionWithName {
dweb_host_string: web_name.dweb_host_string.clone(),
history_address,
version: web_name.version,
archive_address,
directory_tree,
#[cfg(feature = "fixed-dweb-hosts")]
is_fixed_webname: false,
}
}
}