mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-12 03:28:13 -07:00
54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
use std::path::Path;
|
|
|
|
use brk_error::Result;
|
|
use brk_traversable::Traversable;
|
|
use brk_types::Version;
|
|
use vecdb::{Database, PAGE_SIZE};
|
|
|
|
use super::{
|
|
ActivityVecs, AdjustedVecs, CapVecs, PricingVecs, SupplyVecs, ValueVecs, Vecs, DB_NAME,
|
|
};
|
|
use crate::{indexes, price};
|
|
|
|
impl Vecs {
|
|
pub fn forced_import(
|
|
parent_path: &Path,
|
|
parent_version: Version,
|
|
indexes: &indexes::Vecs,
|
|
price: Option<&price::Vecs>,
|
|
) -> Result<Self> {
|
|
let db = Database::open(&parent_path.join(DB_NAME))?;
|
|
db.set_min_len(PAGE_SIZE * 1_000_000)?;
|
|
|
|
let compute_dollars = price.is_some();
|
|
let v0 = parent_version;
|
|
let v1 = parent_version + Version::ONE;
|
|
|
|
let activity = ActivityVecs::forced_import(&db, v0, indexes)?;
|
|
let supply = SupplyVecs::forced_import(&db, v1, indexes, compute_dollars)?;
|
|
let value = ValueVecs::forced_import(&db, v1, indexes)?;
|
|
let cap = CapVecs::forced_import(&db, v1, indexes)?;
|
|
let pricing = PricingVecs::forced_import(&db, v0, indexes, price)?;
|
|
let adjusted = AdjustedVecs::forced_import(&db, v0, indexes)?;
|
|
|
|
let this = Self {
|
|
db,
|
|
activity,
|
|
supply,
|
|
value,
|
|
cap,
|
|
pricing,
|
|
adjusted,
|
|
};
|
|
|
|
this.db.retain_regions(
|
|
this.iter_any_exportable()
|
|
.flat_map(|v| v.region_names())
|
|
.collect(),
|
|
)?;
|
|
this.db.compact()?;
|
|
|
|
Ok(this)
|
|
}
|
|
}
|