docs: tambah doc comment, logging, dan inline comments di semua 255 file
Meliputi: - File-level //! doc comment: tujuan file, alur kerja, komponen utama - Function-level /// doc comment: apa, parameter, return, flow, edge cases - Struct/enum/trait /// doc comment: peran, field docs - Tracing logging (tracing::info!/debug!/trace!/warn!/error!) di setiap fungsi - Inline comments untuk variable dan branching logic penting - Seluruh 8 crates di workspace: zesdex-backend, zesdex-cms, zesdex-entities, zesdex-iam, zesdex-infra, zesdex-ipc, zesdex-middleware, zesdex-utils - Build: 0 errors, 242/242 tests passed
This commit is contained in:
@@ -8,6 +8,9 @@ use rusqlite::{params, Connection};
|
||||
/// Flow: compute current timestamp -> `INSERT OR REPLACE` into `blobs`
|
||||
/// keyed on `(session_id, blob_key)`.
|
||||
///
|
||||
/// `INSERT OR REPLACE` is used so re-uploading the same key overwrites
|
||||
/// the previous blob rather than failing on the UNIQUE constraint.
|
||||
///
|
||||
/// Return: `Ok(())` on success, or the underlying `SQLite` error.
|
||||
pub fn store_blob(
|
||||
conn: &Connection,
|
||||
@@ -17,10 +20,12 @@ pub fn store_blob(
|
||||
mime_type: Option<&str>,
|
||||
) -> Result<()> {
|
||||
let created_at = chrono::Utc::now().timestamp_millis();
|
||||
tracing::debug!(%session_id, %blob_key, size = data.len(), "store_blob");
|
||||
conn.execute(
|
||||
"INSERT OR REPLACE INTO blobs (session_id, blob_key, data, mime_type, created_at) VALUES (?1, ?2, ?3, ?4, ?5)",
|
||||
params![session_id, blob_key, data, mime_type, created_at],
|
||||
)?;
|
||||
tracing::info!(%session_id, %blob_key, "store_blob — stored");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -33,15 +38,25 @@ pub fn retrieve_blob(
|
||||
session_id: &str,
|
||||
blob_key: &str,
|
||||
) -> Result<Option<Vec<u8>>> {
|
||||
tracing::debug!(%session_id, %blob_key, "retrieve_blob");
|
||||
let result = conn.query_row(
|
||||
"SELECT data FROM blobs WHERE session_id = ?1 AND blob_key = ?2",
|
||||
params![session_id, blob_key],
|
||||
|row| row.get(0),
|
||||
|row| row.get::<_, Vec<u8>>(0),
|
||||
);
|
||||
match result {
|
||||
Ok(data) => Ok(Some(data)),
|
||||
Err(rusqlite::Error::QueryReturnedNoRows) => Ok(None),
|
||||
Err(e) => Err(e.into()),
|
||||
Ok(data) => {
|
||||
tracing::debug!(%session_id, %blob_key, size = data.len(), "retrieve_blob — found");
|
||||
Ok(Some(data))
|
||||
}
|
||||
Err(rusqlite::Error::QueryReturnedNoRows) => {
|
||||
tracing::debug!(%session_id, %blob_key, "retrieve_blob — not found");
|
||||
Ok(None)
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!(%session_id, %blob_key, error = %e, "retrieve_blob — query failed");
|
||||
Err(e.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +65,7 @@ pub fn retrieve_blob(
|
||||
/// Return: `Ok(Vec<String>)` of keys ordered by `created_at`, or the
|
||||
/// underlying `SQLite` error.
|
||||
pub fn list_blob_keys(conn: &Connection, session_id: &str) -> Result<Vec<String>> {
|
||||
tracing::debug!(%session_id, "list_blob_keys");
|
||||
let mut stmt =
|
||||
conn.prepare("SELECT blob_key FROM blobs WHERE session_id = ?1 ORDER BY created_at ASC")?;
|
||||
let rows = stmt.query_map(params![session_id], |row| row.get::<_, String>(0))?;
|
||||
@@ -57,5 +73,6 @@ pub fn list_blob_keys(conn: &Connection, session_id: &str) -> Result<Vec<String>
|
||||
for row in rows {
|
||||
keys.push(row?);
|
||||
}
|
||||
tracing::debug!(%session_id, count = keys.len(), "list_blob_keys — done");
|
||||
Ok(keys)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user