Refactor ETag generation for oneliners API

Remove the per-user oneliner watermark, which was previously used to
generate ETags for the `/api/oneliners` endpoint. The watermark was
intended to track the last successful oneliner write for each user.

The ETag generation has been refactored to use a deterministic FNV-1a
hash. This hash is computed over a sorted list of tuples containing
`(case_id, last_recording_at_ns, oneliner_mtime_ns)` for all visible
cases. This approach ensures that the ETag changes whenever any
listen-relevant file system modification occurs, such as a new
recording, oneliner regeneration, soft-delete, undo, or
upload-auto-reopen. This new method is more robust and avoids the
complexity of managing per-user state.

The `OnelinerWatermark` type alias and its associated logic have been
removed from `AppState` and the relevant modules (`transcribe::worker`,
`transcribe::recovery`, `routes::oneliners`, `main`). New integration
tests have been added to verify that various delete operations (single
delete, undo delete, bulk delete) correctly trigger an ETag update,
ensuring cache invalidation.
This commit is contained in:
2026-04-19 14:47:30 +02:00
parent 5e8d2f8e58
commit a1ff410d1b
11 changed files with 425 additions and 80 deletions
+2 -12
View File
@@ -12,7 +12,7 @@ use doctate_server::analyze;
use doctate_server::config::Config;
use doctate_server::gazetteer::{Gazetteer, SpellbookDict};
use doctate_server::transcribe;
use doctate_server::{AppState, OnelinerWatermark};
use doctate_server::AppState;
#[tokio::main]
async fn main() {
@@ -110,13 +110,6 @@ async fn main() {
}
});
// Oneliner watermark: per-user "last successful oneliner write (UTC)".
// Feeds the ETag on `/api/oneliners`. Shared across the transcribe
// worker (writer) and the oneliners route handler (reader).
let oneliner_watermark: OnelinerWatermark = Arc::new(tokio::sync::RwLock::new(
std::collections::HashMap::new(),
));
// Transcription pipeline: channel + worker + recovery scan.
let (transcribe_tx, transcribe_rx) = transcribe::channel();
let transcribe_busy: doctate_server::WorkerBusy =
@@ -127,7 +120,6 @@ async fn main() {
http_client.clone(),
transcribe_busy.clone(),
vocab.clone(),
oneliner_watermark.clone(),
));
{
let tx = transcribe_tx.clone();
@@ -135,13 +127,12 @@ async fn main() {
let client = http_client.clone();
let cfg = config.clone();
let vocab = vocab.clone();
let watermark = oneliner_watermark.clone();
tokio::spawn(async move {
transcribe::recovery::scan_and_enqueue(&data_path, &tx).await;
// Then catch up oneliners for cases that crashed between
// transcript-write and oneliner-write in a previous run.
transcribe::recovery::regenerate_missing_oneliners(
&data_path, &client, &cfg, &vocab, &watermark,
&data_path, &client, &cfg, &vocab,
)
.await;
});
@@ -173,7 +164,6 @@ async fn main() {
session_store: doctate_server::web_session::new_store(),
analyze_busy: doctate_server::AnalyzeBusy(analyze_busy),
transcribe_busy: doctate_server::TranscribeBusy(transcribe_busy),
oneliner_watermark,
};
let addr = format!("0.0.0.0:{}", config.server_port);