server: add date-modified to datasets

This commit is contained in:
k
2024-09-18 17:58:33 +02:00
parent 9b4e166608
commit 41638d10bf
6 changed files with 35 additions and 24 deletions
+1 -1
View File
@@ -264,7 +264,7 @@ impl AllDatasets {
}
pub fn export_meta_files(&self) -> color_eyre::Result<()> {
let path_to_type: BTreeMap<&str, &str> = self
let path_to_type: BTreeMap<&Path, &str> = self
.to_any_dataset_vec()
.into_iter()
.flat_map(|dataset| {
+5 -3
View File
@@ -1,10 +1,12 @@
use std::path::{Path, PathBuf};
pub trait AnyMap {
fn path(&self) -> &str;
fn path_last(&self) -> &Option<String>;
fn path(&self) -> &Path;
fn path_last(&self) -> &Option<PathBuf>;
fn t_name(&self) -> &str;
fn exported_path_with_t_name(&self) -> Vec<(&str, &str)> {
fn exported_path_with_t_name(&self) -> Vec<(&Path, &str)> {
let t_name = self.t_name();
if let Some(path_last) = self.path_last() {
+8 -8
View File
@@ -72,8 +72,8 @@ where
pub struct GenericMap<Key, Value, ChunkId, Serialized> {
version: u32,
path_all: String,
path_last: Option<String>,
path_all: PathBuf,
path_last: Option<PathBuf>,
chunks_in_memory: usize,
@@ -118,13 +118,13 @@ where
let path = path.replace(['-', '_', ' '], "/");
let path_all = format!("{path}/{}", Key::map_name());
let path_all = PathBuf::from(format!("{path}/{}", Key::map_name()));
fs::create_dir_all(&path_all).unwrap();
let path_last = {
if export_last {
Some(format!("{path}/last"))
Some(PathBuf::from(format!("{path}/last")))
} else {
None
}
@@ -184,7 +184,7 @@ where
Self::_read_dir(&self.path_all, &self.serialization)
}
pub fn _read_dir(path: &str, serialization: &Serialization) -> BTreeMap<ChunkId, PathBuf> {
pub fn _read_dir(path: &Path, serialization: &Serialization) -> BTreeMap<ChunkId, PathBuf> {
fs::read_dir(path)
.unwrap()
.map(|entry| entry.unwrap().path())
@@ -278,11 +278,11 @@ where
Key: MapKey<ChunkId>,
Serialized: MapSerialized<Key, Value, ChunkId>,
{
fn path(&self) -> &str {
fn path(&self) -> &Path {
&self.path_all
}
fn path_last(&self) -> &Option<String> {
fn path_last(&self) -> &Option<PathBuf> {
&self.path_last
}
@@ -330,7 +330,7 @@ where
panic!();
});
let path = format!("{}/{}", self.path_all, chunk_id.to_name());
let path = self.path_all.join(chunk_id.to_name());
self.serialization.export(Path::new(&path), serialized)?;
if index == len - 1 {
+15 -6
View File
@@ -95,21 +95,27 @@ fn _dataset_handler(
Kind::Date => {
let datasets = DateMap::<usize>::_read_dir(&route.file_path, &route.serialization);
process_datasets(headers, kind, &mut chunk, &mut route, query, datasets)?;
process_datasets(&headers, kind, &mut chunk, &mut route, query, datasets)?;
}
Kind::Height => {
let datasets =
HeightMap::<usize>::_read_dir(&route.file_path, &route.serialization);
process_datasets(headers, kind, &mut chunk, &mut route, query, datasets)?;
process_datasets(&headers, kind, &mut chunk, &mut route, query, datasets)?;
}
_ => panic!(),
};
}
let (date, response) = headers.check_if_modified_since(&route.file_path).unwrap();
if let Some(response) = response {
return Ok(response);
}
let type_name = route.values_type.split("::").last().unwrap();
let value = match type_name {
let mut response = match type_name {
"u8" => typed_value_to_response::<u8>(kind, &route, chunk)?,
"u16" => typed_value_to_response::<u16>(kind, &route, chunk)?,
"u32" => typed_value_to_response::<u32>(kind, &route, chunk)?,
@@ -123,7 +129,10 @@ fn _dataset_handler(
_ => panic!("Incompatible type: {type_name}"),
};
Ok(value)
let headers = response.headers_mut();
headers.insert_last_modified(date);
Ok(response)
}
fn replace_dash_by_underscore(s: &str) -> String {
@@ -131,7 +140,7 @@ fn replace_dash_by_underscore(s: &str) -> String {
}
fn process_datasets<ChunkId>(
headers: HeaderMap,
headers: &HeaderMap,
kind: Kind,
chunk: &mut Option<Chunk>,
route: &mut Route,
@@ -159,7 +168,7 @@ where
let path = path.unwrap();
route.file_path = path.to_str().unwrap().to_string();
route.file_path = path.clone();
let offset = match kind {
Kind::Date => 1,
+3 -3
View File
@@ -1,7 +1,7 @@
use std::{
collections::{BTreeMap, HashMap},
fs,
path::Path,
path::{Path, PathBuf},
};
use derive_deref::{Deref, DerefMut};
@@ -15,7 +15,7 @@ use super::Paths;
#[derive(Clone, Debug)]
pub struct Route {
pub url_path: String,
pub file_path: String,
pub file_path: PathBuf,
pub values_type: String,
pub serialization: Serialization,
}
@@ -52,7 +52,7 @@ impl Routes {
let url_path = split_key.iter().join("-");
let file_path = key.to_owned();
let file_path = PathBuf::from(key.to_owned());
let values_type = value.to_owned();
if last == "date" {
+3 -3
View File
File diff suppressed because one or more lines are too long