MCPcopy Create free account
hub / github.com/chatmail/core / get_stats

Function get_stats

src/stats.rs:348–390  ·  view source on GitHub ↗
(context: &Context)

Source from the content-addressed store, hash-verified

346}
347
348async fn get_stats(context: &Context) -> Result<String> {
349 // The Id of the last contact that already existed when the user enabled the setting.
350 // Newer contacts will get the `new` flag set.
351 let last_old_contact = context
352 .get_config_u32(Config::StatsLastOldContactId)
353 .await?;
354
355 let self_public_key = load_self_public_key(context).await?;
356 // `key_create_timestamps` is a `Vec` for historical reasons,
357 // support for using multiple keys is being phased out.
358 let key_create_timestamps: Vec<u32> = vec![self_public_key.created_at().as_secs()];
359 let number_of_keys: u32 = context
360 .sql
361 .query_get_value("SELECT COUNT(*) FROM keypairs", ())
362 .await?
363 .unwrap_or(0);
364
365 let sending_enabled_timestamps =
366 get_timestamps(context, "stats_sending_enabled_events").await?;
367 let sending_disabled_timestamps =
368 get_timestamps(context, "stats_sending_disabled_events").await?;
369
370 let stats = Statistics {
371 core_version: DC_VERSION_STR.to_string(),
372 number_of_transports: context.count_transports().await?,
373 key_create_timestamps,
374 number_of_keys,
375 key_version: self_public_key.primary_key.version().into(),
376 key_algorithm: format!("{:?}", self_public_key.algorithm()),
377 pubkey_size: DcKey::to_bytes(&self_public_key).len(),
378 stats_id: stats_id(context).await?,
379 is_chatmail: context.is_chatmail().await?,
380 contact_stats: get_contact_stats(context, last_old_contact).await?,
381 message_stats: get_message_stats(context).await?,
382 securejoin_sources: get_securejoin_source_stats(context).await?,
383 securejoin_uipaths: get_securejoin_uipath_stats(context).await?,
384 securejoin_invites: get_securejoin_invite_stats(context).await?,
385 sending_enabled_timestamps,
386 sending_disabled_timestamps,
387 };
388
389 Ok(serde_json::to_string_pretty(&stats)?)
390}
391
392async fn get_timestamps(context: &Context, sql_table: &str) -> Result<Vec<i64>> {
393 context

Callers 9

send_statsFunction · 0.85
test_stats_one_contactFunction · 0.85
update_get_statsFunction · 0.85
test_message_statsFunction · 0.85
check_statsFunction · 0.85
test_stats_is_chatmailFunction · 0.85
get_timestampsFunction · 0.85
test_cryptography_statsFunction · 0.85

Calls 13

load_self_public_keyFunction · 0.85
stats_idFunction · 0.85
get_contact_statsFunction · 0.85
get_message_statsFunction · 0.85
get_config_u32Method · 0.80
query_get_valueMethod · 0.80
count_transportsMethod · 0.80
get_timestampsFunction · 0.70
lenMethod · 0.45

Tested by 8

test_stats_one_contactFunction · 0.68
update_get_statsFunction · 0.68
test_message_statsFunction · 0.68
check_statsFunction · 0.68
test_stats_is_chatmailFunction · 0.68
get_timestampsFunction · 0.68
test_cryptography_statsFunction · 0.68