MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / get_active_inactive

Function get_active_inactive

chirpstack/src/storage/device.rs:873–898  ·  view source on GitHub ↗
(tenant_id: &Option<Uuid>)

Source from the content-addressed store, hash-verified

871
872#[cfg(feature = "postgres")]
873pub async fn get_active_inactive(tenant_id: &Option<Uuid>) -> Result<DevicesActiveInactive, Error> {
874 diesel::sql_query(r#"
875 with device_active_inactive as (
876 select
877 make_interval(secs => dp.uplink_interval) * 1.5 as uplink_interval,
878 d.last_seen_at as last_seen_at
879 from
880 device d
881 inner join device_profile dp
882 on d.device_profile_id = dp.id
883 inner join application a
884 on d.application_id = a.id
885 where
886 $1 is null or a.tenant_id = $1
887 )
888 select
889 coalesce(sum(case when last_seen_at is null then 1 end), 0) as never_seen_count,
890 coalesce(sum(case when (now() - uplink_interval) > last_seen_at then 1 end), 0) as inactive_count,
891 coalesce(sum(case when (now() - uplink_interval) <= last_seen_at then 1 end), 0) as active_count
892 from
893 device_active_inactive
894 "#)
895 .bind::<diesel::sql_types::Nullable<fields::sql_types::Uuid>, _>(tenant_id.map(fields::Uuid::from))
896 .get_result(&mut get_async_db_conn().await?).await
897 .map_err(|e| Error::from_diesel(e, "".into()))
898}
899
900#[cfg(feature = "sqlite")]
901pub async fn get_active_inactive(tenant_id: &Option<Uuid>) -> Result<DevicesActiveInactive, Error> {

Callers 1

get_devices_summaryMethod · 0.85

Calls 2

get_async_db_connFunction · 0.70
intoMethod · 0.45

Tested by

no test coverage detected