mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-11 14:41:16 -07:00
server: use etag for vecs instead of date modified
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)?)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user