···285285 .await?;
286286287287 let stream = futures::stream::iter(ops).map(|op| {
288288- let mut json = serde_json::to_string(&op).unwrap();
288288+ let mut json = serde_json::to_string(&op.to_sequenced_json()).unwrap();
289289 json.push('\n');
290290 Ok::<_, std::io::Error>(json)
291291 });
···340340 // check that the provided cursor is not stale
341341 if (chrono::Utc::now() - created_at).num_days() > 1 {
342342 return Err(Error::from_string(
343343- format!("cursor {cursor} is stale, catch up using /export first"),
343343+ format!(
344344+ "cursor {cursor} is stale (older than a day), catch up using /export first"
345345+ ),
344346 StatusCode::BAD_REQUEST,
345347 ));
346348 }
···382384 });
383385384386 while let Some(op) = op_rx.recv().await {
385385- cursor = op.seq;
386386- let json = serde_json::to_string(&op).unwrap();
387387+ let json = serde_json::to_string(&op.to_sequenced_json()).unwrap();
387388 if let Err(e) = socket.send(Message::Text(json)).await {
388389 log::warn!("closing export stream: {e}");
389390 return;
390391 }
392392+ cursor = op.seq;
391393 }
392394393395 tokio::select! {
+16-2
src/plc_fjall.rs
···834834 pub seq: u64,
835835 pub did: String,
836836 pub cid: String,
837837+ #[serde(rename = "createdAt")]
837838 pub created_at: Dt,
838839 pub nullified: bool,
839840 pub operation: serde_json::Value,
841841+}
842842+843843+impl Op {
844844+ /// adds the `type` field to the op
845845+ pub fn to_sequenced_json(&self) -> serde_json::Value {
846846+ let mut val = serde_json::to_value(self).expect("Op is serializable");
847847+ if let serde_json::Value::Object(ref mut map) = val {
848848+ map.insert("type".to_string(), "sequenced_op".into());
849849+ }
850850+ val
851851+ }
840852}
841853842854#[derive(Clone)]
···1313132513141326 // we can start two threads, one for forward iteration and one for reverse iteration
13151327 // this way we have two scans in parallel which should be faster!
13161316- let f_handle = spawn_scan_thread!(next, 0, false, ops / 2);
13171317- let b_handle = spawn_scan_thread!(next_back, workers / 2, true, ops - (ops / 2));
13281328+ let f_count = ops / 2;
13291329+ let f_handle = spawn_scan_thread!(next, 0, false, f_count);
13301330+ let b_count = ops - f_count;
13311331+ let b_handle = spawn_scan_thread!(next_back, workers / 2, true, b_count);
1318133213191333 f_handle.join().unwrap()?;
13201334 b_handle.join().unwrap()?;