Skip to content

Commit 79da468

Browse files
committed
fixed using serde skip serialize if attribute
1 parent 88ab9cf commit 79da468

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

adview-manager/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ impl Manager {
411411
.collect::<Vec<_>>()
412412
.join("&");
413413

414-
415414
// Url adds a trailing `/`
416415
let url = format!(
417416
"{}units-for-slot/{}?pubPrefix={}&{}",

primitives/src/sentry.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,12 @@ pub struct ChannelListResponse {
133133
#[serde(rename_all = "camelCase")]
134134
pub struct LastApprovedResponse {
135135
pub last_approved: Option<LastApproved>,
136+
/// None -> withHeartbeat=true wasn't passed
137+
/// Some(vec![]) (empty vec) or Some(heartbeats) - withHeartbeats=true was passed
138+
#[serde(default, skip_serializing_if = "Option::is_none")]
136139
pub heartbeats: Option<Vec<HeartbeatValidatorMessage>>,
137140
}
138141

139-
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
140-
#[serde(rename_all = "camelCase")]
141-
pub struct LastApprovedResponseNoHeartbeats {
142-
pub last_approved: Option<LastApproved>,
143-
}
144-
145142
#[derive(Serialize, Deserialize, Debug)]
146143
pub struct SuccessResponse {
147144
pub success: bool,

primitives/src/targeting/eval.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ impl Into<SerdeValue> for Value {
130130
Value::Bool(bool) => SerdeValue::Bool(bool),
131131
Value::Number(number) => SerdeValue::Number(number),
132132
Value::String(string) => SerdeValue::String(string),
133-
Value::Array(array) => SerdeValue::Array(array.into_iter().map(|value| value.into()).collect()),
134-
Value::BigNum(bignum) => SerdeValue::String(bignum.to_string())
133+
Value::Array(array) => {
134+
SerdeValue::Array(array.into_iter().map(|value| value.into()).collect())
135+
}
136+
Value::BigNum(bignum) => SerdeValue::String(bignum.to_string()),
135137
}
136138
}
137139
}

sentry/src/routes/channel.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use primitives::{
1010
adapter::Adapter,
1111
sentry::{
1212
channel_list::{ChannelListQuery, LastApprovedQuery},
13-
Event, LastApproved, LastApprovedResponse, SuccessResponse, LastApprovedResponseNoHeartbeats,
13+
Event, LastApproved, LastApprovedResponse, SuccessResponse,
1414
},
1515
validator::MessageTypes,
1616
Channel, ChannelId,
@@ -151,34 +151,28 @@ pub async fn last_approved<A: Adapter>(
151151
let query = serde_urlencoded::from_str::<LastApprovedQuery>(&req.uri().query().unwrap_or(""))?;
152152
let validators = channel.spec.validators;
153153
let channel_id = channel.id;
154-
let response_body = if query.with_heartbeat.is_some() {
154+
let heartbeats = if query.with_heartbeat.is_some() {
155155
let result = try_join_all(
156156
validators
157157
.iter()
158158
.map(|validator| latest_heartbeats(&app.pool, &channel_id, &validator.id)),
159159
)
160160
.await?;
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-
})?
161+
Some(result.into_iter().flatten().collect::<Vec<_>>())
169162
} else {
170-
serde_json::to_string(&LastApprovedResponseNoHeartbeats {
171-
last_approved: Some(LastApproved {
172-
new_state,
173-
approve_state: Some(approve_state),
174-
})
175-
})?
163+
None
176164
};
177165

178166
Ok(Response::builder()
179167
.header("Content-type", "application/json")
180168
.body(
181-
response_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+
})?
182176
.into(),
183177
)
184178
.unwrap())

0 commit comments

Comments
 (0)