Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions crates/api/routes_v3/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,10 @@ pub(crate) fn convert_site_view(site_view: SiteView) -> SiteViewV3 {

let counts = SiteAggregates {
site_id: SiteIdV3(site.id.0),
users: local_site.users.into(),
posts: local_site.posts.into(),
comments: local_site.comments.into(),
communities: local_site.communities.into(),
users: local_site.local_users.into(),
posts: local_site.local_posts.into(),
comments: local_site.local_comments.into(),
communities: local_site.local_communities.into(),
users_active_day: local_site.users_active_day.into(),
users_active_week: local_site.users_active_week.into(),
users_active_month: local_site.users_active_month.into(),
Expand Down
2 changes: 1 addition & 1 deletion crates/db_schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ diesel-derive-newtype = { workspace = true, optional = true }
diesel-async = { workspace = true, optional = true }
diesel-uplete = { workspace = true, optional = true }
diesel_ltree = { workspace = true, optional = true }
ts-rs = { workspace = true, optional = true }
ts-rs = { workspace = true, optional = true, features = ["serde-json-impl"] }
tokio = { workspace = true, optional = true }
i-love-jesus = { workspace = true, optional = true }
derive-new.workspace = true
Expand Down
18 changes: 9 additions & 9 deletions crates/db_schema/src/impls/local_site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ mod tests {

// TODO: this is unstable, sometimes it returns 0 users, sometimes 1
//assert_eq!(0, site_aggregates_before_delete.users);
assert_eq!(1, site_aggregates_before_delete.communities);
assert_eq!(2, site_aggregates_before_delete.posts);
assert_eq!(2, site_aggregates_before_delete.comments);
assert_eq!(1, site_aggregates_before_delete.local_communities);
assert_eq!(2, site_aggregates_before_delete.local_posts);
assert_eq!(2, site_aggregates_before_delete.local_comments);

// Try a post delete
Post::delete(pool, inserted_post.id).await?;
let site_aggregates_after_post_delete = read_local_site(pool).await?;
assert_eq!(1, site_aggregates_after_post_delete.posts);
assert_eq!(0, site_aggregates_after_post_delete.comments);
assert_eq!(1, site_aggregates_after_post_delete.local_posts);
assert_eq!(0, site_aggregates_after_post_delete.local_comments);

// This shouuld delete all the associated rows, and fire triggers
let person_num_deleted = Person::delete(pool, inserted_person.id).await?;
Expand Down Expand Up @@ -163,7 +163,7 @@ mod tests {
let (data, inserted_person, inserted_community) = prepare_site_with_community(pool).await?;

let site_aggregates_before = read_local_site(pool).await?;
assert_eq!(1, site_aggregates_before.communities);
assert_eq!(1, site_aggregates_before.local_communities);

Community::update(
pool,
Expand All @@ -176,7 +176,7 @@ mod tests {
.await?;

let site_aggregates_after_delete = read_local_site(pool).await?;
assert_eq!(0, site_aggregates_after_delete.communities);
assert_eq!(0, site_aggregates_after_delete.local_communities);

Community::update(
pool,
Expand All @@ -199,7 +199,7 @@ mod tests {
.await?;

let site_aggregates_after_remove = read_local_site(pool).await?;
assert_eq!(0, site_aggregates_after_remove.communities);
assert_eq!(0, site_aggregates_after_remove.local_communities);

Community::update(
pool,
Expand All @@ -212,7 +212,7 @@ mod tests {
.await?;

let site_aggregates_after_remove_delete = read_local_site(pool).await?;
assert_eq!(0, site_aggregates_after_remove_delete.communities);
assert_eq!(0, site_aggregates_after_remove_delete.local_communities);

Community::delete(pool, inserted_community.id).await?;
Person::delete(pool, inserted_person.id).await?;
Expand Down
19 changes: 15 additions & 4 deletions crates/db_schema/src/source/local_site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use lemmy_db_schema_file::{
},
};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_with::skip_serializing_none;

#[skip_serializing_none]
Expand Down Expand Up @@ -78,10 +79,10 @@ pub struct LocalSite {
pub default_post_time_range_seconds: Option<i32>,
/// Block NSFW content being created
pub disallow_nsfw_content: bool,
pub users: i32,
pub posts: i32,
pub comments: i32,
pub communities: i32,
pub local_users: i32,
pub local_posts: i32,
pub local_comments: i32,
pub local_communities: i32,
/// The number of users with any activity in the last day.
pub users_active_day: i32,
/// The number of users with any activity in the last week.
Expand Down Expand Up @@ -113,6 +114,16 @@ pub struct LocalSite {
/// This affects post and comment images, but not avatars and banners.
pub image_allow_video_uploads: bool,
pub image_upload_disabled: bool,
pub linked_instances: i32,
pub total_posts: i32,
pub total_comments: i32,
pub total_users: i32,
pub total_communities: i32,
pub user_retention_percent: i32,
pub ban_rate: i32,
pub accepted_signups_rate: i32,
pub failed_signups_rate: i32,
pub language_usage_percent: Value,
}

#[derive(Clone, derive_new::new)]
Expand Down
18 changes: 14 additions & 4 deletions crates/db_schema_file/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,10 @@ diesel::table! {
comment_downvotes -> FederationModeEnum,
default_post_time_range_seconds -> Nullable<Int4>,
disallow_nsfw_content -> Bool,
users -> Int4,
posts -> Int4,
comments -> Int4,
communities -> Int4,
local_users -> Int4,
local_posts -> Int4,
local_comments -> Int4,
local_communities -> Int4,
users_active_day -> Int4,
users_active_week -> Int4,
users_active_month -> Int4,
Expand All @@ -427,6 +427,16 @@ diesel::table! {
image_max_upload_size -> Int4,
image_allow_video_uploads -> Bool,
image_upload_disabled -> Bool,
linked_instances -> Int4,
total_posts -> Int4,
total_comments -> Int4,
total_users -> Int4,
total_communities -> Int4,
user_retention_percent -> Int4,
ban_rate -> Int4,
accepted_signups_rate -> Int4,
failed_signups_rate -> Int4,
language_usage_percent -> Jsonb,
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/diesel_utils/replaceable_schema/triggers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ WHERE
UPDATE
local_site AS a
SET
comments = a.comments + diff.comments
local_comments = a.local_comments + diff.comments
FROM (
SELECT
coalesce(sum(count_diff), 0) AS comments
Expand Down Expand Up @@ -223,7 +223,7 @@ WHERE
UPDATE
local_site AS a
SET
posts = a.posts + diff.posts
local_posts = a.local_posts + diff.posts
FROM (
SELECT
coalesce(sum(count_diff), 0) AS posts
Expand All @@ -242,7 +242,7 @@ BEGIN
UPDATE
local_site AS a
SET
communities = a.communities + diff.communities
local_communities = a.local_communities + diff.communities
FROM (
SELECT
coalesce(sum(count_diff), 0) AS communities
Expand Down
1 change: 1 addition & 0 deletions crates/routes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ diesel-uplete.workspace = true
lemmy_diesel_utils = { workspace = true }
rosetta-i18n = { workspace = true }
strum = { workspace = true }
serde_json = { workspace = true }

[dev-dependencies]
pretty_assertions.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/routes/src/nodeinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ async fn node_info(context: web::Data<LemmyContext>) -> Result<HttpResponse, Err
protocols: Some(vec!["activitypub".to_string()]),
usage: Some(NodeInfoUsage {
users: Some(NodeInfoUsers {
total: Some(site_view.local_site.users),
total: Some(site_view.local_site.local_users),
active_halfyear: Some(site_view.local_site.users_active_half_year),
active_month: Some(site_view.local_site.users_active_month),
}),
local_posts: Some(site_view.local_site.posts),
local_comments: Some(site_view.local_site.comments),
local_posts: Some(site_view.local_site.local_posts),
local_comments: Some(site_view.local_site.local_comments),
}),
open_registrations,
services: Some(NodeInfoServices {
Expand Down
Loading