use super::{
apply_post_commit_effects_with_failures, note_reindex_effect, CommittedPostCommitEffects,
KhiveRuntime, NamespaceToken, PostCommitEffect, PostCommitEmbeddingOutcome, RuntimeResult,
};
pub async fn apply_post_commit_effects(
runtime: &KhiveRuntime,
token: &NamespaceToken,
effects: CommittedPostCommitEffects,
) -> RuntimeResult<()> {
apply_post_commit_effects_with_report(runtime, token, effects)
.await
.map(|_| ())
}
pub async fn apply_post_commit_effects_with_report(
runtime: &KhiveRuntime,
token: &NamespaceToken,
effects: CommittedPostCommitEffects,
) -> RuntimeResult<Vec<PostCommitEmbeddingOutcome>> {
let report = apply_post_commit_effects_with_failures(runtime, token, effects).await;
match report.failure_error() {
Some(error) => Err(error),
None => Ok(report.outcomes),
}
}
pub(super) async fn apply_one_post_commit_effect(
runtime: &KhiveRuntime,
token: &NamespaceToken,
effect: PostCommitEffect,
) -> RuntimeResult<Option<PostCommitEmbeddingOutcome>> {
match effect {
PostCommitEffect::None => Ok(None),
PostCommitEffect::NoteChanged { note_id, kind } => {
runtime.fire_note_mutation_hook(&kind, note_id).await;
Ok(None)
}
PostCommitEffect::ReindexEntity { entity_id } => {
let Some(entity) = runtime.entities(token)?.get_entity(entity_id).await? else {
return Ok(None);
};
let truncation = runtime.reindex_entity(token, &entity).await?;
Ok(Some(PostCommitEmbeddingOutcome {
effect: PostCommitEffect::ReindexEntity { entity_id },
truncation,
failures: Vec::new(),
}))
}
PostCommitEffect::ReindexNote { note_id, version } => {
note_reindex_effect::apply(runtime, token, note_id, version).await
}
PostCommitEffect::NoteDeleted { note_id, kind } => {
runtime.fire_note_mutation_hook(&kind, note_id).await;
Ok(None)
}
PostCommitEffect::GtdAudit { .. } => {
Ok(None)
}
}
}