tidaldb/tidal/src/db/storage_box.rs
jordan 192c473f55 feat: complete Milestone 5 — full-text search, RRF fusion, and creator search
- M5p1: BM25 text indexing via Tantivy with background syncer (0.26ms @ 10K docs)
- M5p2: RRF fusion layer combining BM25 + ANN scores (46µs @ 1K candidates)
- M5p3: unified Search query API (8-stage pipeline, BM25 + vector + ranking)
- M5p4: creator text + vector indexing and creator search executor (< 20ms @ 200 creators)
- Refactor db/mod.rs into focused sub-modules (creators, items, sessions, signals, etc.)
- Decompose monolithic files into directory modules (query/executor, ranking/diversity, etc.)
- Split brute.rs → brute/mod.rs + brute/tests.rs; extract search executor helpers
- Add benches: fusion, search, session, text_index
- Add M5 UAT test suites (m5_uat, m5_search, m5p4_creator_search, text_index)
- Update blog posts, roadmap, content strategy, and M5 planning docs
- Add tmp/ and .claude/worktrees/ to .gitignore

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 23:53:16 -07:00

54 lines
1.7 KiB
Rust

//! Storage abstraction: routes to the correct backend by entity kind.
use crate::schema::{EntityKind, TidalError};
use crate::storage::{InMemoryBackend, StorageEngine};
/// Wraps either in-memory backends (ephemeral mode) or a fjall storage
/// (persistent mode) behind a uniform interface.
///
/// M3 provides three backends: items, users, creators. In ephemeral mode
/// each is an independent `InMemoryBackend`; in persistent mode they share
/// a single `FjallStorage` with three keyspaces.
pub enum StorageBox {
Memory {
items: InMemoryBackend,
users: InMemoryBackend,
creators: InMemoryBackend,
},
Fjall(crate::storage::FjallStorage),
}
impl StorageBox {
/// Reference to the items storage engine.
pub(super) fn items_engine(&self) -> &dyn StorageEngine {
match self {
Self::Memory { items, .. } => items,
Self::Fjall(f) => f.backend(EntityKind::Item),
}
}
/// Reference to the users storage engine.
pub(super) fn users_engine(&self) -> &dyn StorageEngine {
match self {
Self::Memory { users, .. } => users,
Self::Fjall(f) => f.backend(EntityKind::User),
}
}
/// Reference to the creators storage engine.
pub(super) fn creators_engine(&self) -> &dyn StorageEngine {
match self {
Self::Memory { creators, .. } => creators,
Self::Fjall(f) => f.backend(EntityKind::Creator),
}
}
/// Flush all buffered writes to durable storage.
pub(super) fn flush(&self) -> crate::Result<()> {
match self {
Self::Memory { .. } => Ok(()),
Self::Fjall(f) => f.flush_all().map_err(TidalError::from),
}
}
}