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

Function get_count

chirpstack/src/storage/device.rs:633–719  ·  view source on GitHub ↗
(filters: &Filters)

Source from the content-addressed store, hash-verified

631}
632
633pub async fn get_count(filters: &Filters) -> Result<i64, Error> {
634 let mut q = device::dsl::device
635 .select(dsl::count_star())
636 .distinct()
637 .inner_join(application::table)
638 .left_join(multicast_group_device::table)
639 .into_boxed();
640
641 // Filter by user permissions
642 if let Some(user_id) = &filters.user_id {
643 q = q.filter(dsl::exists(
644 user::table
645 .filter(
646 user::id
647 .eq(fields::Uuid::from(user_id))
648 .and(user::is_active.eq(true)),
649 )
650 .filter(
651 user::is_admin.eq(true).or(dsl::exists(
652 tenant_user::table
653 .filter(
654 tenant_user::user_id
655 .eq(user::id)
656 .and(tenant_user::tenant_id.eq(application::tenant_id)),
657 )
658 .filter(
659 tenant_user::is_admin
660 .eq(true)
661 .or(tenant_user::is_device_admin.eq(true))
662 .or(dsl::exists(
663 tenant_user_application::table.filter(
664 tenant_user_application::user_id.eq(user::id).and(
665 tenant_user_application::application_id
666 .eq(application::id),
667 ),
668 ),
669 )),
670 ),
671 )),
672 ),
673 ));
674 }
675
676 if let Some(application_id) = &filters.application_id {
677 q = q.filter(device::dsl::application_id.eq(fields::Uuid::from(application_id)));
678 }
679
680 if let Some(device_profile_id) = &filters.device_profile_id {
681 q = q.filter(device::dsl::device_profile_id.eq(fields::Uuid::from(device_profile_id)));
682 }
683
684 if let Some(search) = &filters.search {
685 #[cfg(feature = "postgres")]
686 {
687 q = q.filter(device::dsl::name.ilike(format!("%{}%", search)));
688 }
689 #[cfg(feature = "sqlite")]
690 {

Callers 1

test_device_listFunction · 0.70

Calls 3

containsMethod · 0.80
iterMethod · 0.80
get_async_db_connFunction · 0.70

Tested by 1

test_device_listFunction · 0.56