fix: statistics at the top of page
This commit is contained in:
parent
44b322371c
commit
15cc1f708f
5 changed files with 147 additions and 96 deletions
|
|
@ -30,7 +30,12 @@ pub async fn list_realms_with_owner(
|
|||
r.owner_id,
|
||||
u.username as owner_username,
|
||||
r.member_count,
|
||||
r.current_user_count,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::INTEGER
|
||||
FROM scene.instance_members im
|
||||
JOIN realm.scenes s ON im.instance_id = s.id
|
||||
WHERE s.realm_id = r.id
|
||||
), 0) AS current_user_count,
|
||||
r.created_at
|
||||
FROM realm.realms r
|
||||
JOIN auth.users u ON r.owner_id = u.id
|
||||
|
|
@ -65,7 +70,12 @@ pub async fn search_realms(
|
|||
r.owner_id,
|
||||
u.username as owner_username,
|
||||
r.member_count,
|
||||
r.current_user_count,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::INTEGER
|
||||
FROM scene.instance_members im
|
||||
JOIN realm.scenes s ON im.instance_id = s.id
|
||||
WHERE s.realm_id = r.id
|
||||
), 0) AS current_user_count,
|
||||
r.created_at
|
||||
FROM realm.realms r
|
||||
JOIN auth.users u ON r.owner_id = u.id
|
||||
|
|
@ -245,7 +255,12 @@ pub async fn get_realm_by_slug(pool: &PgPool, slug: &str) -> Result<RealmDetail,
|
|||
r.max_users,
|
||||
r.allow_guest_access,
|
||||
r.member_count,
|
||||
r.current_user_count,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::INTEGER
|
||||
FROM scene.instance_members im
|
||||
JOIN realm.scenes s ON im.instance_id = s.id
|
||||
WHERE s.realm_id = r.id
|
||||
), 0) AS current_user_count,
|
||||
r.created_at,
|
||||
r.updated_at
|
||||
FROM realm.realms r
|
||||
|
|
@ -317,7 +332,12 @@ pub async fn update_realm(
|
|||
r.max_users,
|
||||
r.allow_guest_access,
|
||||
r.member_count,
|
||||
r.current_user_count,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::INTEGER
|
||||
FROM scene.instance_members im
|
||||
JOIN realm.scenes s ON im.instance_id = s.id
|
||||
WHERE s.realm_id = r.id
|
||||
), 0) AS current_user_count,
|
||||
r.created_at,
|
||||
r.updated_at
|
||||
FROM realm.realms r
|
||||
|
|
|
|||
|
|
@ -262,17 +262,22 @@ pub async fn list_all_realms(pool: &PgPool) -> Result<Vec<RealmSummary>, AppErro
|
|||
let realms = sqlx::query_as::<_, RealmSummary>(
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
tagline,
|
||||
privacy,
|
||||
is_nsfw,
|
||||
thumbnail_path,
|
||||
member_count,
|
||||
current_user_count
|
||||
FROM realm.realms
|
||||
ORDER BY name
|
||||
r.id,
|
||||
r.name,
|
||||
r.slug,
|
||||
r.tagline,
|
||||
r.privacy,
|
||||
r.is_nsfw,
|
||||
r.thumbnail_path,
|
||||
r.member_count,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::INTEGER
|
||||
FROM scene.instance_members im
|
||||
JOIN realm.scenes s ON im.instance_id = s.id
|
||||
WHERE s.realm_id = r.id
|
||||
), 0) AS current_user_count
|
||||
FROM realm.realms r
|
||||
ORDER BY r.name
|
||||
"#,
|
||||
)
|
||||
.fetch_all(pool)
|
||||
|
|
|
|||
|
|
@ -77,27 +77,32 @@ pub async fn get_realm_by_slug<'e>(
|
|||
let realm = sqlx::query_as::<_, Realm>(
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
description,
|
||||
tagline,
|
||||
owner_id,
|
||||
privacy,
|
||||
is_nsfw,
|
||||
min_reputation_tier,
|
||||
theme_color,
|
||||
banner_image_path,
|
||||
thumbnail_path,
|
||||
max_users,
|
||||
allow_guest_access,
|
||||
default_scene_id,
|
||||
member_count,
|
||||
current_user_count,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM realm.realms
|
||||
WHERE slug = $1
|
||||
r.id,
|
||||
r.name,
|
||||
r.slug,
|
||||
r.description,
|
||||
r.tagline,
|
||||
r.owner_id,
|
||||
r.privacy,
|
||||
r.is_nsfw,
|
||||
r.min_reputation_tier,
|
||||
r.theme_color,
|
||||
r.banner_image_path,
|
||||
r.thumbnail_path,
|
||||
r.max_users,
|
||||
r.allow_guest_access,
|
||||
r.default_scene_id,
|
||||
r.member_count,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::INTEGER
|
||||
FROM scene.instance_members im
|
||||
JOIN realm.scenes s ON im.instance_id = s.id
|
||||
WHERE s.realm_id = r.id
|
||||
), 0) AS current_user_count,
|
||||
r.created_at,
|
||||
r.updated_at
|
||||
FROM realm.realms r
|
||||
WHERE r.slug = $1
|
||||
"#,
|
||||
)
|
||||
.bind(slug)
|
||||
|
|
@ -112,27 +117,32 @@ pub async fn get_realm_by_id(pool: &PgPool, id: Uuid) -> Result<Option<Realm>, A
|
|||
let realm = sqlx::query_as::<_, Realm>(
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
description,
|
||||
tagline,
|
||||
owner_id,
|
||||
privacy,
|
||||
is_nsfw,
|
||||
min_reputation_tier,
|
||||
theme_color,
|
||||
banner_image_path,
|
||||
thumbnail_path,
|
||||
max_users,
|
||||
allow_guest_access,
|
||||
default_scene_id,
|
||||
member_count,
|
||||
current_user_count,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM realm.realms
|
||||
WHERE id = $1
|
||||
r.id,
|
||||
r.name,
|
||||
r.slug,
|
||||
r.description,
|
||||
r.tagline,
|
||||
r.owner_id,
|
||||
r.privacy,
|
||||
r.is_nsfw,
|
||||
r.min_reputation_tier,
|
||||
r.theme_color,
|
||||
r.banner_image_path,
|
||||
r.thumbnail_path,
|
||||
r.max_users,
|
||||
r.allow_guest_access,
|
||||
r.default_scene_id,
|
||||
r.member_count,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::INTEGER
|
||||
FROM scene.instance_members im
|
||||
JOIN realm.scenes s ON im.instance_id = s.id
|
||||
WHERE s.realm_id = r.id
|
||||
), 0) AS current_user_count,
|
||||
r.created_at,
|
||||
r.updated_at
|
||||
FROM realm.realms r
|
||||
WHERE r.id = $1
|
||||
"#,
|
||||
)
|
||||
.bind(id)
|
||||
|
|
@ -153,18 +163,23 @@ pub async fn list_public_realms(
|
|||
sqlx::query_as::<_, RealmSummary>(
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
tagline,
|
||||
privacy,
|
||||
is_nsfw,
|
||||
thumbnail_path,
|
||||
member_count,
|
||||
current_user_count
|
||||
FROM realm.realms
|
||||
WHERE privacy = 'public'
|
||||
ORDER BY current_user_count DESC, member_count DESC
|
||||
r.id,
|
||||
r.name,
|
||||
r.slug,
|
||||
r.tagline,
|
||||
r.privacy,
|
||||
r.is_nsfw,
|
||||
r.thumbnail_path,
|
||||
r.member_count,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::INTEGER
|
||||
FROM scene.instance_members im
|
||||
JOIN realm.scenes s ON im.instance_id = s.id
|
||||
WHERE s.realm_id = r.id
|
||||
), 0) AS current_user_count
|
||||
FROM realm.realms r
|
||||
WHERE r.privacy = 'public'
|
||||
ORDER BY current_user_count DESC, r.member_count DESC
|
||||
LIMIT $1 OFFSET $2
|
||||
"#,
|
||||
)
|
||||
|
|
@ -176,18 +191,23 @@ pub async fn list_public_realms(
|
|||
sqlx::query_as::<_, RealmSummary>(
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
tagline,
|
||||
privacy,
|
||||
is_nsfw,
|
||||
thumbnail_path,
|
||||
member_count,
|
||||
current_user_count
|
||||
FROM realm.realms
|
||||
WHERE privacy = 'public' AND is_nsfw = false
|
||||
ORDER BY current_user_count DESC, member_count DESC
|
||||
r.id,
|
||||
r.name,
|
||||
r.slug,
|
||||
r.tagline,
|
||||
r.privacy,
|
||||
r.is_nsfw,
|
||||
r.thumbnail_path,
|
||||
r.member_count,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::INTEGER
|
||||
FROM scene.instance_members im
|
||||
JOIN realm.scenes s ON im.instance_id = s.id
|
||||
WHERE s.realm_id = r.id
|
||||
), 0) AS current_user_count
|
||||
FROM realm.realms r
|
||||
WHERE r.privacy = 'public' AND r.is_nsfw = false
|
||||
ORDER BY current_user_count DESC, r.member_count DESC
|
||||
LIMIT $1 OFFSET $2
|
||||
"#,
|
||||
)
|
||||
|
|
@ -205,18 +225,23 @@ pub async fn get_user_realms(pool: &PgPool, user_id: Uuid) -> Result<Vec<RealmSu
|
|||
let realms = sqlx::query_as::<_, RealmSummary>(
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
tagline,
|
||||
privacy,
|
||||
is_nsfw,
|
||||
thumbnail_path,
|
||||
member_count,
|
||||
current_user_count
|
||||
FROM realm.realms
|
||||
WHERE owner_id = $1
|
||||
ORDER BY created_at DESC
|
||||
r.id,
|
||||
r.name,
|
||||
r.slug,
|
||||
r.tagline,
|
||||
r.privacy,
|
||||
r.is_nsfw,
|
||||
r.thumbnail_path,
|
||||
r.member_count,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::INTEGER
|
||||
FROM scene.instance_members im
|
||||
JOIN realm.scenes s ON im.instance_id = s.id
|
||||
WHERE s.realm_id = r.id
|
||||
), 0) AS current_user_count
|
||||
FROM realm.realms r
|
||||
WHERE r.owner_id = $1
|
||||
ORDER BY r.created_at DESC
|
||||
"#,
|
||||
)
|
||||
.bind(user_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue