use cognee_database::IngestDb;
use uuid::Uuid;
use crate::types::{SearchContext, SearchError};
pub async fn update_node_access_timestamps(
database: &dyn IngestDb,
context: &SearchContext,
) -> Result<(), SearchError> {
let now = chrono::Utc::now();
let data_ids: Vec<Uuid> = context
.iter()
.filter_map(|item| {
item.payload
.get("data_id")
.or_else(|| item.payload.get("document_id"))
.and_then(|v| v.as_str())
.and_then(|s| Uuid::parse_str(s).ok())
})
.collect();
if data_ids.is_empty() {
return Ok(());
}
database
.update_last_accessed(&data_ids, now)
.await
.map_err(|e| SearchError::DatabaseError(e.to_string()))
}