server: use etag for vecs instead of date modified

This commit is contained in:
nym21
2025-06-24 10:11:03 +02:00
parent 0f3c267a48
commit 016d80e002
45 changed files with 132 additions and 181 deletions

View File

@@ -1,6 +1,4 @@
use std::time::Duration;
use brk_core::{Result, Version};
use brk_core::Version;
use super::{BoxedVecIterator, StoredIndex, StoredType};
@@ -11,9 +9,23 @@ pub trait AnyVec: Send + Sync {
fn is_empty(&self) -> bool {
self.len() == 0
}
fn modified_time(&self) -> Result<Duration>;
fn index_type_to_string(&self) -> &'static str;
fn value_type_to_size_of(&self) -> usize;
fn etag(&self, to: Option<i64>) -> String {
let len = self.len();
format!(
"{}-{:?}",
to.map_or(len, |to| {
if to.is_negative() {
len.checked_sub(to.unsigned_abs() as usize)
.unwrap_or_default()
} else {
to as usize
}
}),
self.version()
)
}
}
pub trait AnyIterableVec<I, T>: AnyVec {

View File

@@ -3,7 +3,6 @@ use std::{
io::{self, Seek, SeekFrom, Write},
path::{Path, PathBuf},
sync::Arc,
time::{self, Duration},
};
use arc_swap::ArcSwap;
@@ -168,12 +167,4 @@ where
fn flush(&mut self) -> Result<()>;
fn truncate_if_needed(&mut self, index: I) -> Result<()>;
fn modified_time_(&self) -> Result<Duration> {
Ok(self
.file()
.metadata()?
.modified()?
.duration_since(time::UNIX_EPOCH)?)
}
}