Skip to content

Commit b0687fd

Browse files
committed
Skip serializing bot, direct_chat, and new if they are false
1 parent 46a5ff7 commit b0687fd

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/statistics.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,30 @@ struct ContactStat {
5353
id: ContactId,
5454

5555
verified: VerifiedStatus,
56+
57+
// If one of the boolean properties is false,
58+
// we leave them away.
59+
// This way, the Json file becomes a lot smaller.
60+
#[serde(skip_serializing_if = "is_false")]
5661
bot: bool,
62+
63+
#[serde(skip_serializing_if = "is_false")]
5764
direct_chat: bool,
65+
5866
last_seen: u64,
5967

6068
#[serde(skip_serializing_if = "Option::is_none")]
6169
transitive_chain: Option<u32>,
6270

6371
/// Whether the contact was established after stats-sending was enabled
72+
#[serde(skip_serializing_if = "is_false")]
6473
new: bool,
6574
}
6675

76+
fn is_false(b: &bool) -> bool {
77+
!b
78+
}
79+
6780
#[derive(Serialize)]
6881
struct MessageStats {
6982
to_verified: u32,
@@ -379,8 +392,8 @@ async fn get_contact_stats(context: &Context, last_old_contact: u32) -> Result<V
379392
.sql
380393
.exists(
381394
"SELECT COUNT(*)
382-
FROM chats_contacts cc INNER JOIN chats
383-
WHERE cc.contact_id=? AND chats.type=?",
395+
FROM chats_contacts cc INNER JOIN chats
396+
WHERE cc.contact_id=? AND chats.type=?",
384397
(contact.id, Chattype::Single),
385398
)
386399
.await?;

src/statistics/statistics_tests.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ async fn test_statistics_one_contact() -> Result<()> {
7070
let contact_stats = r2.get("contact_stats").unwrap().as_array().unwrap();
7171
assert_eq!(contact_stats.len(), 1);
7272
let contact_info = &contact_stats[0];
73-
assert_eq!(
74-
contact_info.get("bot").unwrap(),
75-
&serde_json::Value::Bool(false)
76-
);
73+
assert!(contact_info.get("bot").is_none());
7774
assert_eq!(
7875
contact_info.get("direct_chat").unwrap(),
7976
&serde_json::Value::Bool(true)

0 commit comments

Comments
 (0)