mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-11 06:39:08 -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)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ use std::{
|
||||
mem,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use arc_swap::{ArcSwap, Guard};
|
||||
@@ -381,11 +380,6 @@ where
|
||||
self.len_()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn modified_time(&self) -> Result<Duration> {
|
||||
self.modified_time_()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn index_type_to_string(&self) -> &'static str {
|
||||
I::to_string()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{fs, path::Path, time::Duration};
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use brk_exit::Exit;
|
||||
use clap_derive::ValueEnum;
|
||||
@@ -245,15 +245,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn modified_time(&self) -> Result<Duration> {
|
||||
match self {
|
||||
ComputedVec::Eager { vec, .. } => vec.modified_time(),
|
||||
ComputedVec::LazyFrom1(v) => v.modified_time(),
|
||||
ComputedVec::LazyFrom2(v) => v.modified_time(),
|
||||
ComputedVec::LazyFrom3(v) => v.modified_time(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn value_type_to_size_of(&self) -> usize {
|
||||
size_of::<T>()
|
||||
|
||||
@@ -5,7 +5,6 @@ use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, Div, Mul},
|
||||
path::{Path, PathBuf},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
@@ -1304,11 +1303,6 @@ where
|
||||
self.0.len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn modified_time(&self) -> Result<Duration> {
|
||||
self.0.modified_time()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn index_type_to_string(&self) -> &'static str {
|
||||
I::to_string()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{cmp::Ordering, fmt::Debug, path::Path, time::Duration};
|
||||
use std::{cmp::Ordering, fmt::Debug, path::Path};
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
use brk_core::{Error, Height, Result, Value, Version};
|
||||
@@ -103,11 +103,6 @@ where
|
||||
self.0.len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn modified_time(&self) -> Result<Duration> {
|
||||
self.0.modified_time()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn index_type_to_string(&self) -> &'static str {
|
||||
I::to_string()
|
||||
|
||||
@@ -143,10 +143,6 @@ where
|
||||
self.source.len()
|
||||
}
|
||||
|
||||
fn modified_time(&self) -> Result<std::time::Duration> {
|
||||
self.source.modified_time()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn value_type_to_size_of(&self) -> usize {
|
||||
size_of::<T>()
|
||||
|
||||
@@ -188,13 +188,6 @@ where
|
||||
len1.min(len2)
|
||||
}
|
||||
|
||||
fn modified_time(&self) -> Result<std::time::Duration> {
|
||||
Ok(self
|
||||
.source1
|
||||
.modified_time()?
|
||||
.min(self.source2.modified_time()?))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn value_type_to_size_of(&self) -> usize {
|
||||
size_of::<T>()
|
||||
|
||||
@@ -222,14 +222,6 @@ where
|
||||
len1.min(len2).min(len3)
|
||||
}
|
||||
|
||||
fn modified_time(&self) -> Result<std::time::Duration> {
|
||||
Ok(self
|
||||
.source1
|
||||
.modified_time()?
|
||||
.min(self.source2.modified_time()?)
|
||||
.min(self.source3.modified_time()?))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn value_type_to_size_of(&self) -> usize {
|
||||
size_of::<T>()
|
||||
|
||||
@@ -5,7 +5,6 @@ use std::{
|
||||
mem,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use arc_swap::{ArcSwap, Guard};
|
||||
@@ -250,11 +249,6 @@ where
|
||||
self.len_()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn modified_time(&self) -> Result<Duration> {
|
||||
self.modified_time_()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn index_type_to_string(&self) -> &'static str {
|
||||
I::to_string()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::{
|
||||
fs::File,
|
||||
path::{Path, PathBuf},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
@@ -191,14 +190,6 @@ where
|
||||
self.pushed_len() + self.stored_len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn modified_time(&self) -> Result<Duration> {
|
||||
match self {
|
||||
StoredVec::Raw(v) => v.modified_time(),
|
||||
StoredVec::Compressed(v) => v.modified_time(),
|
||||
}
|
||||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
match self {
|
||||
StoredVec::Raw(v) => v.name(),
|
||||
|
||||
Reference in New Issue
Block a user