throttle updates

main
Zynh0722 2023-11-06 17:54:10 -08:00
parent 239b332b48
commit c31c8e91ac
2 changed files with 5 additions and 2 deletions

View File

@ -18,7 +18,7 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tower-http = { version = "0.4.4", features = ["full"] } tower-http = { version = "0.4.4", features = ["full"] }
ructe.workspace = true ructe.workspace = true
tokio-stream = { version = "0.1.14", features = ["sync"] } tokio-stream = { version = "0.1.14", features = ["sync", "time"] }
futures-util = "0.3.28" futures-util = "0.3.28"
diesel = { version = "2.1.0", features = ["chrono"] } diesel = { version = "2.1.0", features = ["chrono"] }
diesel-async = { version = "0.4.1", features = ["mysql", "deadpool"] } diesel-async = { version = "0.4.1", features = ["mysql", "deadpool"] }

View File

@ -1,3 +1,5 @@
use std::time::Duration;
use axum::{ use axum::{
extract::{Path, State}, extract::{Path, State},
response::{ response::{
@ -182,7 +184,8 @@ async fn ada_subscribe(
State(state): State<AppState>, State(state): State<AppState>,
) -> Sse<impl Stream<Item = Result<Event, BroadcastStreamRecvError>>> { ) -> Sse<impl Stream<Item = Result<Event, BroadcastStreamRecvError>>> {
let stream = BroadcastStream::new(state.sse_handler.ada_sender.subscribe()) let stream = BroadcastStream::new(state.sse_handler.ada_sender.subscribe())
.map(|r| r.map(|s| Event::default().event("ada").data(s))); .map(|r| r.map(|s| Event::default().event("ada").data(s)))
.throttle(Duration::from_secs(1));
Sse::new(stream).keep_alive(KeepAlive::default()) Sse::new(stream).keep_alive(KeepAlive::default())
} }