@@ -10,7 +10,7 @@ use primitives::{
10
10
adapter:: Adapter ,
11
11
sentry:: {
12
12
channel_list:: { ChannelListQuery , LastApprovedQuery } ,
13
- Event , LastApproved , LastApprovedResponse , SuccessResponse ,
13
+ Event , LastApproved , LastApprovedResponse , SuccessResponse , LastApprovedResponseNoHeartbeats ,
14
14
} ,
15
15
validator:: MessageTypes ,
16
16
Channel , ChannelId ,
@@ -151,28 +151,34 @@ pub async fn last_approved<A: Adapter>(
151
151
let query = serde_urlencoded:: from_str :: < LastApprovedQuery > ( & req. uri ( ) . query ( ) . unwrap_or ( "" ) ) ?;
152
152
let validators = channel. spec . validators ;
153
153
let channel_id = channel. id ;
154
- let heartbeats = if query. with_heartbeat . is_some ( ) {
154
+ let response_body = if query. with_heartbeat . is_some ( ) {
155
155
let result = try_join_all (
156
156
validators
157
157
. iter ( )
158
158
. map ( |validator| latest_heartbeats ( & app. pool , & channel_id, & validator. id ) ) ,
159
159
)
160
160
. await ?;
161
- Some ( result. into_iter ( ) . flatten ( ) . collect :: < Vec < _ > > ( ) )
161
+ let heartbeats = Some ( result. into_iter ( ) . flatten ( ) . collect :: < Vec < _ > > ( ) ) ;
162
+ serde_json:: to_string ( & LastApprovedResponse {
163
+ last_approved : Some ( LastApproved {
164
+ new_state,
165
+ approve_state : Some ( approve_state) ,
166
+ } ) ,
167
+ heartbeats,
168
+ } ) ?
162
169
} else {
163
- None
170
+ serde_json:: to_string ( & LastApprovedResponseNoHeartbeats {
171
+ last_approved : Some ( LastApproved {
172
+ new_state,
173
+ approve_state : Some ( approve_state) ,
174
+ } )
175
+ } ) ?
164
176
} ;
165
177
166
178
Ok ( Response :: builder ( )
167
179
. header ( "Content-type" , "application/json" )
168
180
. body (
169
- serde_json:: to_string ( & LastApprovedResponse {
170
- last_approved : Some ( LastApproved {
171
- new_state,
172
- approve_state : Some ( approve_state) ,
173
- } ) ,
174
- heartbeats,
175
- } ) ?
181
+ response_body
176
182
. into ( ) ,
177
183
)
178
184
. unwrap ( ) )
0 commit comments