use crate::config::Config;
#[cfg(feature = "documents")]
use crate::scanner_docs::flush_document_batches;
use crate::scanner_drive::{PendingCodeBatchOpt, PendingDocBatchOpt};
use crate::store::Store;
pub(crate) fn maintain_lance_if_open(store: &Store) {
#[cfg(any(feature = "documents", feature = "code-search"))]
if let Some(lance) = store.lance.as_ref()
&& let Err(error) = lance.maintain(crate::lance::SCAN_RETENTION)
{
tracing::warn!(?error, "lance post-scan maintenance failed; old table versions kept");
}
#[cfg(not(any(feature = "documents", feature = "code-search")))]
let _ = store;
}
#[cfg(feature = "documents")]
pub(crate) fn flush_doc_batches_if_any(store: &mut Store, config: &Config, batches: Vec<PendingDocBatchOpt>) {
if batches.is_empty() {
return;
}
crate::scanner_doc_links::flush_doc_links(store, config, &batches);
let _ = flush_document_batches(store, batches, &config.documents.embedding_preset);
}
#[cfg(not(feature = "documents"))]
pub(crate) fn flush_doc_batches_if_any(_store: &mut Store, _config: &Config, _batches: Vec<PendingDocBatchOpt>) {}
#[cfg(feature = "documents")]
pub(crate) fn flush_doc_removals_if_any(store: &mut Store, config: &Config, scope: &str, stale: &[String]) {
crate::scanner_docs::delete_stale_documents(store, config, scope, stale);
}
#[cfg(feature = "code-search")]
pub(crate) fn flush_code_batches_if_any(
store: &mut Store,
config: &Config,
scope: &str,
batches: Vec<PendingCodeBatchOpt>,
) {
if batches.is_empty() {
return;
}
let _ = crate::scanner_code::flush_code_batches(store, scope, batches, &config.documents.embedding_preset);
}
#[cfg(not(feature = "code-search"))]
pub(crate) fn flush_code_batches_if_any(
_store: &mut Store,
_config: &Config,
_scope: &str,
_batches: Vec<PendingCodeBatchOpt>,
) {
}
#[cfg(feature = "code-search")]
pub(crate) fn flush_code_removals_if_any(store: &mut Store, config: &Config, scope: &str, stale: &[String]) {
crate::scanner_code::delete_stale_code_chunks(store, config, scope, stale);
}
#[cfg(not(feature = "code-search"))]
pub(crate) fn flush_code_removals_if_any(_store: &mut Store, _config: &Config, _scope: &str, _stale: &[String]) {}
#[cfg(feature = "code-search")]
pub(crate) fn finalize_bm25_stats_if_any(store: &Store, config: &Config) {
if !crate::scanner_code::should_chunk(config) {
return;
}
if let Some(db) = store.index_db.as_ref()
&& let Err(error) = db.recompute_bm25_stats()
{
tracing::warn!(?error, "recompute bm25 stats failed; keyword search may be stale");
}
}
#[cfg(not(feature = "code-search"))]
pub(crate) fn finalize_bm25_stats_if_any(_store: &Store, _config: &Config) {}