mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-28 08:39:59 -07:00
Merge branch 'main' into dockerize
This commit is contained in:
@@ -36,10 +36,9 @@ impl Bridge for Interface<'static> {
|
||||
// File auto-generated, any modifications will be overwritten
|
||||
//
|
||||
|
||||
export const VERSION = \"v{}\";
|
||||
export const VERSION = \"v{VERSION}\";
|
||||
|
||||
",
|
||||
VERSION
|
||||
"
|
||||
);
|
||||
|
||||
contents += &indexes
|
||||
@@ -53,7 +52,7 @@ export const VERSION = \"v{}\";
|
||||
.join("\n");
|
||||
|
||||
contents += &format!(
|
||||
"\n\n/** @typedef {{{}}} Index */",
|
||||
"\n\n/** @typedef {{{}}} Index */\n",
|
||||
indexes
|
||||
.iter()
|
||||
.map(|i| i.to_string())
|
||||
@@ -61,12 +60,35 @@ export const VERSION = \"v{}\";
|
||||
.join(" | ")
|
||||
);
|
||||
|
||||
contents += "\n\n/** @typedef {ReturnType<typeof createVecIdToIndexes>} VecIdToIndexes */";
|
||||
contents += "\n/** @typedef {keyof VecIdToIndexes} VecId */\n";
|
||||
contents += "
|
||||
/** @typedef {ReturnType<typeof createIndexes>} Indexes */
|
||||
|
||||
contents += "\nexport function createVecIdToIndexes() {\n";
|
||||
export function createIndexes() {
|
||||
return {
|
||||
";
|
||||
|
||||
contents += " return {\n";
|
||||
contents += &indexes
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i_of_i, i)| {
|
||||
let lowered = i.to_string().to_lowercase();
|
||||
format!(" {lowered}: /** @satisfies {{{i}}} */ ({i_of_i}),",)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
||||
contents += " };\n}\n";
|
||||
|
||||
contents += "
|
||||
/** @typedef {ReturnType<typeof createVecIdToIndexes>} VecIdToIndexes
|
||||
/** @typedef {keyof VecIdToIndexes} VecId */
|
||||
|
||||
/**
|
||||
* @returns {Record<any, number[]>}
|
||||
*/
|
||||
export function createVecIdToIndexes() {
|
||||
return {
|
||||
";
|
||||
|
||||
self.id_to_index_to_vec()
|
||||
.iter()
|
||||
|
||||
@@ -4,9 +4,7 @@ use axum::{
|
||||
http::{HeaderMap, StatusCode},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use brk_core::DateIndex;
|
||||
use brk_interface::{Format, Output, Params};
|
||||
use brk_vec::{CollectableVec, StoredVec};
|
||||
use color_eyre::eyre::eyre;
|
||||
|
||||
use crate::traits::{HeaderMapExtended, ResponseExtended};
|
||||
@@ -50,20 +48,19 @@ fn req_to_response_res(
|
||||
let to = params.to();
|
||||
let format = params.format();
|
||||
|
||||
// TODO: From and to should be capped here
|
||||
|
||||
let weight = vecs
|
||||
.iter()
|
||||
.map(|(_, v)| {
|
||||
let len = v.len();
|
||||
let count = StoredVec::<DateIndex, usize>::range_count(from, to, len);
|
||||
count * v.value_type_to_size_of()
|
||||
})
|
||||
.map(|(_, v)| v.range_weight(from, to))
|
||||
.sum::<usize>();
|
||||
|
||||
if weight > MAX_WEIGHT {
|
||||
return Err(eyre!("Request is too heavy, max weight is {MAX_WEIGHT}"));
|
||||
}
|
||||
|
||||
let etag = vecs.first().unwrap().1.etag(to);
|
||||
// TODO: height should be from vec, but good enough for now
|
||||
let etag = vecs.first().unwrap().1.etag(interface.get_height(), to);
|
||||
|
||||
if headers
|
||||
.get_if_none_match()
|
||||
|
||||
Reference in New Issue
Block a user