From c96017c00942a9d28570d5762c65725524a0caa4 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Thu, 23 May 2024 14:46:26 +0200 Subject: [PATCH] Configure max comment width in clippy (#4738) * Configure max comment width in clippy * update default config --- .rustfmt.toml | 2 + config/defaults.hjson | 12 +++--- crates/api/src/local_user/save_settings.rs | 3 +- crates/api_common/src/build_response.rs | 3 +- crates/api_common/src/person.rs | 6 ++- crates/api_common/src/site.rs | 3 +- crates/api_common/src/utils.rs | 7 +-- crates/api_crud/src/site/update.rs | 3 +- crates/api_crud/src/user/create.rs | 3 +- .../activities/community/collection_add.rs | 4 +- crates/apub/src/activities/community/mod.rs | 7 +-- .../activities/create_or_update/comment.rs | 3 +- .../src/collections/community_featured.rs | 3 +- .../apub/src/collections/community_outbox.rs | 3 +- crates/apub/src/objects/post.rs | 3 +- .../activities/deletion/delete_user.rs | 3 +- crates/db_perf/src/main.rs | 3 +- crates/db_perf/src/series.rs | 8 ++-- crates/db_schema/src/impls/community.rs | 3 +- crates/db_schema/src/impls/instance.rs | 8 ++-- crates/db_schema/src/impls/person.rs | 3 +- crates/db_schema/src/schema_setup.rs | 28 ++++++------ crates/db_schema/src/source/comment.rs | 3 +- crates/db_schema/src/source/local_user.rs | 3 +- crates/db_schema/src/source/mod.rs | 3 +- crates/db_schema/src/source/site.rs | 3 +- crates/db_schema/src/traits.rs | 7 +-- crates/db_schema/src/utils.rs | 27 ++++++++---- crates/db_views/src/comment_report_view.rs | 3 +- crates/db_views/src/comment_view.rs | 5 ++- crates/db_views/src/post_report_view.rs | 3 +- crates/db_views/src/post_view.rs | 30 +++++++------ .../src/private_message_report_view.rs | 3 +- .../src/registration_application_view.rs | 3 +- crates/db_views/src/structs.rs | 7 +-- .../src/community_follower_view.rs | 11 +++-- crates/db_views_actor/src/community_view.rs | 2 +- crates/federate/src/lib.rs | 9 ++-- crates/federate/src/util.rs | 13 +++--- crates/federate/src/worker.rs | 43 ++++++++++++------- crates/utils/src/error.rs | 3 +- crates/utils/src/lib.rs | 3 +- crates/utils/src/rate_limit/rate_limiter.rs | 26 ++++++----- crates/utils/src/settings/structs.rs | 15 ++++--- crates/utils/src/utils/slurs.rs | 4 +- src/api_routes_http.rs | 3 +- src/lib.rs | 21 +++++---- src/scheduled_tasks.rs | 9 ++-- 48 files changed, 236 insertions(+), 147 deletions(-) diff --git a/.rustfmt.toml b/.rustfmt.toml index 80c01a69b..dfeeb3bfd 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -3,3 +3,5 @@ edition = "2021" imports_layout = "HorizontalVertical" imports_granularity = "Crate" group_imports = "One" +wrap_comments = true +comment_width = 100 diff --git a/config/defaults.hjson b/config/defaults.hjson index 1fbab1fb9..e8a70ebae 100644 --- a/config/defaults.hjson +++ b/config/defaults.hjson @@ -47,7 +47,8 @@ # # To be removed in 0.20 cache_external_link_previews: true - # Specifies how to handle remote images, so that users don't have to connect directly to remote servers. + # Specifies how to handle remote images, so that users don't have to connect directly to remote + # servers. image_mode: # Leave images unchanged, don't generate any local thumbnails for post urls. Instead the # Opengraph image is directly returned as thumbnail @@ -64,10 +65,11 @@ # or - # If enabled, all images from remote domains are rewritten to pass through `/api/v3/image_proxy`, - # including embedded images in markdown. Images are stored temporarily in pict-rs for caching. - # This improves privacy as users don't expose their IP to untrusted servers, and decreases load - # on other servers. However it increases bandwidth use for the local server. + # If enabled, all images from remote domains are rewritten to pass through + # `/api/v3/image_proxy`, including embedded images in markdown. Images are stored temporarily + # in pict-rs for caching. This improves privacy as users don't expose their IP to untrusted + # servers, and decreases load on other servers. However it increases bandwidth use for the + # local server. # # Requires pict-rs 0.5 "ProxyAllImages" diff --git a/crates/api/src/local_user/save_settings.rs b/crates/api/src/local_user/save_settings.rs index 609d52742..bdba817cc 100644 --- a/crates/api/src/local_user/save_settings.rs +++ b/crates/api/src/local_user/save_settings.rs @@ -72,7 +72,8 @@ pub async fn save_user_settings( } } - // When the site requires email, make sure email is not Some(None). IE, an overwrite to a None value + // When the site requires email, make sure email is not Some(None). IE, an overwrite to a None + // value if let Some(email) = &email { if email.is_none() && site_view.local_site.require_email_verification { Err(LemmyErrorType::EmailRequired)? diff --git a/crates/api_common/src/build_response.rs b/crates/api_common/src/build_response.rs index f77a90882..85cf065eb 100644 --- a/crates/api_common/src/build_response.rs +++ b/crates/api_common/src/build_response.rs @@ -121,7 +121,8 @@ pub async fn send_local_notifs( if let Ok(Some(mention_user_view)) = user_view { // TODO // At some point, make it so you can't tag the parent creator either - // Potential duplication of notifications, one for reply and the other for mention, is handled below by checking recipient ids + // Potential duplication of notifications, one for reply and the other for mention, is handled + // below by checking recipient ids recipient_ids.push(mention_user_view.local_user.id); let user_mention_form = PersonMentionInsertForm { diff --git a/crates/api_common/src/person.rs b/crates/api_common/src/person.rs index cad30ca2c..f61f784c2 100644 --- a/crates/api_common/src/person.rs +++ b/crates/api_common/src/person.rs @@ -124,7 +124,8 @@ pub struct SaveUserSettings { pub post_listing_mode: Option, /// Whether to allow keyboard navigation (for browsing and interacting with posts and comments). pub enable_keyboard_navigation: Option, - /// Whether user avatars or inline images in the UI that are gifs should be allowed to play or should be paused + /// Whether user avatars or inline images in the UI that are gifs should be allowed to play or + /// should be paused pub enable_animated_images: Option, /// Whether to auto-collapse bot comments. pub collapse_bot_comments: Option, @@ -151,7 +152,8 @@ pub struct ChangePassword { #[cfg_attr(feature = "full", ts(export))] /// A response for your login. pub struct LoginResponse { - /// This is None in response to `Register` if email verification is enabled, or the server requires registration applications. + /// This is None in response to `Register` if email verification is enabled, or the server + /// requires registration applications. pub jwt: Option, /// If registration applications are required, this will return true for a signup response. pub registration_created: bool, diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index d87cbdaaf..77bfcd8ee 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -375,7 +375,8 @@ impl From for ReadableFederationState { pub struct InstanceWithFederationState { #[serde(flatten)] pub instance: Instance, - /// if federation to this instance is or was active, show state of outgoing federation to this instance + /// if federation to this instance is or was active, show state of outgoing federation to this + /// instance pub federation_state: Option, } diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index f1e9c4c04..d66ce1700 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -356,7 +356,8 @@ pub async fn build_federated_instances( federation_state: federation_state.map(std::convert::Into::into), }; if is_blocked { - // blocked instances will only have an entry here if they had been federated with in the past. + // blocked instances will only have an entry here if they had been federated with in the + // past. blocked.push(i); } else if is_allowed { allowed.push(i.clone()); @@ -954,8 +955,8 @@ pub async fn process_markdown_opt( /// A wrapper for `proxy_image_link` for use in tests. /// -/// The parameter `force_image_proxy` is the config value of `pictrs.image_proxy`. Its necessary to pass -/// as separate parameter so it can be changed in tests. +/// The parameter `force_image_proxy` is the config value of `pictrs.image_proxy`. Its necessary to +/// pass as separate parameter so it can be changed in tests. async fn proxy_image_link_internal( link: Url, image_mode: PictrsImageMode, diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index 7b44b92a6..7efa9b568 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -156,7 +156,8 @@ pub async fn update_site( // TODO can't think of a better way to do this. // If the server suddenly requires email verification, or required applications, no old users // will be able to log in. It really only wants this to be a requirement for NEW signups. - // So if it was set from false, to true, you need to update all current users columns to be verified. + // So if it was set from false, to true, you need to update all current users columns to be + // verified. let old_require_application = local_site.registration_mode == RegistrationMode::RequireApplication; diff --git a/crates/api_crud/src/user/create.rs b/crates/api_crud/src/user/create.rs index 206ce241b..bf064fb2e 100644 --- a/crates/api_crud/src/user/create.rs +++ b/crates/api_crud/src/user/create.rs @@ -197,7 +197,8 @@ pub async fn register( verify_email_sent: false, }; - // Log the user in directly if the site is not setup, or email verification and application aren't required + // Log the user in directly if the site is not setup, or email verification and application aren't + // required if !local_site.site_setup || (!require_registration_application && !local_site.require_email_verification) { diff --git a/crates/apub/src/activities/community/collection_add.rs b/crates/apub/src/activities/community/collection_add.rs index 3d5de4128..4048a1469 100644 --- a/crates/apub/src/activities/community/collection_add.rs +++ b/crates/apub/src/activities/community/collection_add.rs @@ -138,8 +138,8 @@ impl ActivityHandler for CollectionAdd { .dereference(context) .await?; - // If we had to refetch the community while parsing the activity, then the new mod has already - // been added. Skip it here as it would result in a duplicate key error. + // If we had to refetch the community while parsing the activity, then the new mod has + // already been added. Skip it here as it would result in a duplicate key error. let new_mod_id = new_mod.id; let moderated_communities = CommunityModerator::get_person_moderated_communities(&mut context.pool(), new_mod_id) diff --git a/crates/apub/src/activities/community/mod.rs b/crates/apub/src/activities/community/mod.rs index a47dec2bd..59b8fadbb 100644 --- a/crates/apub/src/activities/community/mod.rs +++ b/crates/apub/src/activities/community/mod.rs @@ -24,13 +24,14 @@ pub mod update; /// /// Activities are sent to the community itself if it lives on another instance. If the community /// is local, the activity is directly wrapped into Announce and sent to community followers. -/// Activities are also sent to those who follow the actor (with exception of moderation activities). +/// Activities are also sent to those who follow the actor (with exception of moderation +/// activities). /// /// * `activity` - The activity which is being sent /// * `actor` - The user who is sending the activity /// * `community` - Community inside which the activity is sent -/// * `inboxes` - Any additional inboxes the activity should be sent to (for example, -/// to the user who is being promoted to moderator) +/// * `inboxes` - Any additional inboxes the activity should be sent to (for example, to the user +/// who is being promoted to moderator) /// * `is_mod_activity` - True for things like Add/Mod, these are not sent to user followers pub(crate) async fn send_activity_in_community( activity: AnnouncableActivities, diff --git a/crates/apub/src/activities/create_or_update/comment.rs b/crates/apub/src/activities/create_or_update/comment.rs index b86e32d49..2406d2eb3 100644 --- a/crates/apub/src/activities/create_or_update/comment.rs +++ b/crates/apub/src/activities/create_or_update/comment.rs @@ -176,7 +176,8 @@ impl ActivityHandler for CreateOrUpdateNote { // Although mentions could be gotten from the post tags (they are included there), or the ccs, // Its much easier to scrape them from the comment body, since the API has to do that // anyway. - // TODO: for compatibility with other projects, it would be much better to read this from cc or tags + // TODO: for compatibility with other projects, it would be much better to read this from cc or + // tags let mentions = scrape_text_for_mentions(&comment.content); send_local_notifs(mentions, comment.id, &actor, do_send_email, context).await?; Ok(()) diff --git a/crates/apub/src/collections/community_featured.rs b/crates/apub/src/collections/community_featured.rs index eb19d64ea..e092693e6 100644 --- a/crates/apub/src/collections/community_featured.rs +++ b/crates/apub/src/collections/community_featured.rs @@ -72,7 +72,8 @@ impl Collection for ApubCommunityFeatured { .to_vec(); } - // process items in parallel, to avoid long delay from fetch_site_metadata() and other processing + // process items in parallel, to avoid long delay from fetch_site_metadata() and other + // processing let stickied_posts: Vec = join_all(pages.into_iter().map(|page| { async { // use separate request counter for each item, otherwise there will be problems with diff --git a/crates/apub/src/collections/community_outbox.rs b/crates/apub/src/collections/community_outbox.rs index 6b66c0859..8aca82d38 100644 --- a/crates/apub/src/collections/community_outbox.rs +++ b/crates/apub/src/collections/community_outbox.rs @@ -102,7 +102,8 @@ impl Collection for ApubCommunityOutbox { // We intentionally ignore errors here. This is because the outbox might contain posts from old // Lemmy versions, or from other software which we cant parse. In that case, we simply skip the // item and only parse the ones that work. - // process items in parallel, to avoid long delay from fetch_site_metadata() and other processing + // process items in parallel, to avoid long delay from fetch_site_metadata() and other + // processing join_all(outbox_activities.into_iter().map(|activity| { async { // Receiving announce requires at least one local community follower for anti spam purposes. diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 0931349b6..3f69fa0c8 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -259,7 +259,8 @@ impl Object for ApubPost { let post_ = post.clone(); let context_ = context.reset_request_count(); - // Generates a post thumbnail in background task, because some sites can be very slow to respond. + // Generates a post thumbnail in background task, because some sites can be very slow to + // respond. spawn_try_task(async move { generate_post_link_metadata(post_, None, |_| None, local_site, context_).await }); diff --git a/crates/apub/src/protocol/activities/deletion/delete_user.rs b/crates/apub/src/protocol/activities/deletion/delete_user.rs index 46b070fab..70bba0718 100644 --- a/crates/apub/src/protocol/activities/deletion/delete_user.rs +++ b/crates/apub/src/protocol/activities/deletion/delete_user.rs @@ -23,6 +23,7 @@ pub struct DeleteUser { #[serde(deserialize_with = "deserialize_one_or_many", default)] #[serde(skip_serializing_if = "Vec::is_empty")] pub(crate) cc: Vec, - /// Nonstandard field. If present, all content from the user should be deleted along with the account + /// Nonstandard field. If present, all content from the user should be deleted along with the + /// account pub(crate) remove_data: Option, } diff --git a/crates/db_perf/src/main.rs b/crates/db_perf/src/main.rs index 6139fc18e..9092d7514 100644 --- a/crates/db_perf/src/main.rs +++ b/crates/db_perf/src/main.rs @@ -132,7 +132,8 @@ async fn try_main() -> LemmyResult<()> { // Make sure the println above shows the correct amount assert_eq!(num_inserted_posts, num_posts as usize); - // Manually trigger and wait for a statistics update to ensure consistent and high amount of accuracy in the statistics used for query planning + // Manually trigger and wait for a statistics update to ensure consistent and high amount of + // accuracy in the statistics used for query planning println!("🧮 updating database statistics"); conn.batch_execute("ANALYZE;").await?; diff --git a/crates/db_perf/src/series.rs b/crates/db_perf/src/series.rs index 0dcddbd9f..b504efc54 100644 --- a/crates/db_perf/src/series.rs +++ b/crates/db_perf/src/series.rs @@ -14,10 +14,12 @@ use diesel::{ /// Gererates a series of rows for insertion. /// -/// An inclusive range is created from `start` and `stop`. A row for each number is generated using `selection`, which can be a tuple. -/// [`current_value`] is an expression that gets the current value. +/// An inclusive range is created from `start` and `stop`. A row for each number is generated using +/// `selection`, which can be a tuple. [`current_value`] is an expression that gets the current +/// value. /// -/// For example, if there's a `numbers` table with a `number` column, this inserts all numbers from 1 to 10 in a single statement: +/// For example, if there's a `numbers` table with a `number` column, this inserts all numbers from +/// 1 to 10 in a single statement: /// /// ``` /// dsl::insert_into(numbers::table) diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index e886098ce..02b65e6fc 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -141,7 +141,8 @@ impl Community { Ok(community_) } - /// Get the community which has a given moderators or featured url, also return the collection type + /// Get the community which has a given moderators or featured url, also return the collection + /// type pub async fn get_by_collection_url( pool: &mut DbPool<'_>, url: &DbUrl, diff --git a/crates/db_schema/src/impls/instance.rs b/crates/db_schema/src/impls/instance.rs index 67da14823..8d2e4b75a 100644 --- a/crates/db_schema/src/impls/instance.rs +++ b/crates/db_schema/src/impls/instance.rs @@ -117,15 +117,15 @@ impl Instance { .await } - /// returns a list of all instances, each with a flag of whether the instance is allowed or not and dead or not - /// ordered by id + /// returns a list of all instances, each with a flag of whether the instance is allowed or not + /// and dead or not ordered by id pub async fn read_federated_with_blocked_and_dead( pool: &mut DbPool<'_>, ) -> Result, Error> { let conn = &mut get_conn(pool).await?; let is_dead_expr = coalesce(instance::updated, instance::published).lt(now() - 3.days()); - // this needs to be done in two steps because the meaning of the "blocked" column depends on the existence - // of any value at all in the allowlist. (so a normal join wouldn't work) + // this needs to be done in two steps because the meaning of the "blocked" column depends on the + // existence of any value at all in the allowlist. (so a normal join wouldn't work) let use_allowlist = federation_allowlist::table .select(count_star().gt(0)) .get_result::(conn) diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index a4c7073da..0255785d6 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -55,7 +55,8 @@ impl Crud for Person { impl Person { /// Update or insert the person. /// - /// This is necessary for federation, because Activitypub doesn't distinguish between these actions. + /// This is necessary for federation, because Activitypub doesn't distinguish between these + /// actions. pub async fn upsert(pool: &mut DbPool<'_>, form: &PersonInsertForm) -> Result { let conn = &mut get_conn(pool).await?; insert_into(person::table) diff --git a/crates/db_schema/src/schema_setup.rs b/crates/db_schema/src/schema_setup.rs index dc8cdf387..3def94060 100644 --- a/crates/db_schema/src/schema_setup.rs +++ b/crates/db_schema/src/schema_setup.rs @@ -6,18 +6,19 @@ use tracing::info; const MIGRATIONS: EmbeddedMigrations = embed_migrations!(); -/// This SQL code sets up the `r` schema, which contains things that can be safely dropped and replaced -/// instead of being changed using migrations. It may not create or modify things outside of the `r` schema -/// (indicated by `r.` before the name), unless a comment says otherwise. +/// This SQL code sets up the `r` schema, which contains things that can be safely dropped and +/// replaced instead of being changed using migrations. It may not create or modify things outside +/// of the `r` schema (indicated by `r.` before the name), unless a comment says otherwise. /// -/// Currently, this code is only run after the server starts and there's at least 1 pending migration -/// to run. This means every time you change something here, you must also create a migration (a blank -/// up.sql file works fine). This behavior will be removed when we implement a better way to avoid -/// useless schema updates and locks. +/// Currently, this code is only run after the server starts and there's at least 1 pending +/// migration to run. This means every time you change something here, you must also create a +/// migration (a blank up.sql file works fine). This behavior will be removed when we implement a +/// better way to avoid useless schema updates and locks. /// -/// If you add something that depends on something (such as a table) created in a new migration, then down.sql -/// must use `CASCADE` when dropping it. This doesn't need to be fixed in old migrations because the -/// "replaceable-schema" migration runs `DROP SCHEMA IF EXISTS r CASCADE` in down.sql. +/// If you add something that depends on something (such as a table) created in a new migration, +/// then down.sql must use `CASCADE` when dropping it. This doesn't need to be fixed in old +/// migrations because the "replaceable-schema" migration runs `DROP SCHEMA IF EXISTS r CASCADE` in +/// down.sql. const REPLACEABLE_SCHEMA: &[&str] = &[ "DROP SCHEMA IF EXISTS r CASCADE;", "CREATE SCHEMA r;", @@ -29,9 +30,10 @@ pub fn run(db_url: &str) -> Result<(), LemmyError> { // Migrations don't support async connection let mut conn = PgConnection::establish(db_url).with_context(|| "Error connecting to database")?; - // Run all pending migrations except for the newest one, then run the newest one in the same transaction - // as `REPLACEABLE_SCHEMA`. This code will be becone less hacky when the conditional setup of things in - // `REPLACEABLE_SCHEMA` is done without using the number of pending migrations. + // Run all pending migrations except for the newest one, then run the newest one in the same + // transaction as `REPLACEABLE_SCHEMA`. This code will be becone less hacky when the conditional + // setup of things in `REPLACEABLE_SCHEMA` is done without using the number of pending + // migrations. info!("Running Database migrations (This may take a long time)..."); let migrations = conn .pending_migrations(MIGRATIONS) diff --git a/crates/db_schema/src/source/comment.rs b/crates/db_schema/src/source/comment.rs index 3ebea42c1..74ae0b7f6 100644 --- a/crates/db_schema/src/source/comment.rs +++ b/crates/db_schema/src/source/comment.rs @@ -41,7 +41,8 @@ pub struct Comment { #[cfg(feature = "full")] #[cfg_attr(feature = "full", serde(with = "LtreeDef"))] #[cfg_attr(feature = "full", ts(type = "string"))] - /// The path / tree location of a comment, separated by dots, ending with the comment's id. Ex: 0.24.27 + /// The path / tree location of a comment, separated by dots, ending with the comment's id. Ex: + /// 0.24.27 pub path: Ltree, #[cfg(not(feature = "full"))] pub path: String, diff --git a/crates/db_schema/src/source/local_user.rs b/crates/db_schema/src/source/local_user.rs index 8af893b10..5d592ddf1 100644 --- a/crates/db_schema/src/source/local_user.rs +++ b/crates/db_schema/src/source/local_user.rs @@ -62,7 +62,8 @@ pub struct LocalUser { pub totp_2fa_enabled: bool, /// Whether to allow keyboard navigation (for browsing and interacting with posts and comments). pub enable_keyboard_navigation: bool, - /// Whether user avatars and inline images in the UI that are gifs should be allowed to play or should be paused + /// Whether user avatars and inline images in the UI that are gifs should be allowed to play or + /// should be paused pub enable_animated_images: bool, /// Whether to auto-collapse bot comments. pub collapse_bot_comments: bool, diff --git a/crates/db_schema/src/source/mod.rs b/crates/db_schema/src/source/mod.rs index 3a6501717..bbc8aafa2 100644 --- a/crates/db_schema/src/source/mod.rs +++ b/crates/db_schema/src/source/mod.rs @@ -43,7 +43,8 @@ pub mod tagline; /// Default value for columns like [community::Community.inbox_url] which are marked as serde(skip). /// /// This is necessary so they can be successfully deserialized from API responses, even though the -/// value is not sent by Lemmy. Necessary for crates which rely on Rust API such as lemmy-stats-crawler. +/// value is not sent by Lemmy. Necessary for crates which rely on Rust API such as +/// lemmy-stats-crawler. fn placeholder_apub_url() -> DbUrl { DbUrl(Box::new( Url::parse("http://example.com").expect("parse placeholder url"), diff --git a/crates/db_schema/src/source/site.rs b/crates/db_schema/src/source/site.rs index 04c219f2a..325bff97c 100644 --- a/crates/db_schema/src/source/site.rs +++ b/crates/db_schema/src/source/site.rs @@ -76,7 +76,8 @@ pub struct SiteUpdateForm { pub name: Option, pub sidebar: Option>, pub updated: Option>>, - // when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column. + // when you want to null out a column, you have to send Some(None)), since sending None means you + // just don't want to update that column. pub icon: Option>, pub banner: Option>, pub description: Option>, diff --git a/crates/db_schema/src/traits.rs b/crates/db_schema/src/traits.rs index 139ec0e15..2b0da6c7f 100644 --- a/crates/db_schema/src/traits.rs +++ b/crates/db_schema/src/traits.rs @@ -25,8 +25,8 @@ pub type Find = dsl::Find<::Table, ::IdType>; pub type PrimaryKey = <::Table as Table>::PrimaryKey; -// Trying to create default implementations for `create` and `update` results in a lifetime mess and weird compile errors. -// https://github.com/rust-lang/rust/issues/102211 +// Trying to create default implementations for `create` and `update` results in a lifetime mess and +// weird compile errors. https://github.com/rust-lang/rust/issues/102211 #[async_trait] pub trait Crud: HasTable + Sized where @@ -49,7 +49,8 @@ where query.first(conn).await.optional() } - /// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column. + /// when you want to null out a column, you have to send Some(None)), since sending None means you + /// just don't want to update that column. async fn update( pool: &mut DbPool<'_>, id: Self::IdType, diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index e75d7ac51..c6170fcd4 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -61,7 +61,8 @@ pub const RANK_DEFAULT: f64 = 0.0001; pub type ActualDbPool = Pool; -/// References a pool or connection. Functions must take `&mut DbPool<'_>` to allow implicit reborrowing. +/// References a pool or connection. Functions must take `&mut DbPool<'_>` to allow implicit +/// reborrowing. /// /// https://github.com/rust-lang/rfcs/issues/1403 pub enum DbPool<'a> { @@ -101,7 +102,8 @@ impl<'a> DerefMut for DbConn<'a> { } } -// Allows functions that take `DbPool<'_>` to be called in a transaction by passing `&mut conn.into()` +// Allows functions that take `DbPool<'_>` to be called in a transaction by passing `&mut +// conn.into()` impl<'a> From<&'a mut AsyncPgConnection> for DbPool<'a> { fn from(value: &'a mut AsyncPgConnection) -> Self { DbPool::Conn(value) @@ -120,11 +122,13 @@ impl<'a> From<&'a ActualDbPool> for DbPool<'a> { } } -/// Runs multiple async functions that take `&mut DbPool<'_>` as input and return `Result`. Only works when the `futures` crate is listed in `Cargo.toml`. +/// Runs multiple async functions that take `&mut DbPool<'_>` as input and return `Result`. Only +/// works when the `futures` crate is listed in `Cargo.toml`. /// /// `$pool` is the value given to each function. /// -/// A `Result` is returned (not in a `Future`, so don't use `.await`). The `Ok` variant contains a tuple with the values returned by the given functions. +/// A `Result` is returned (not in a `Future`, so don't use `.await`). The `Ok` variant contains a +/// tuple with the values returned by the given functions. /// /// The functions run concurrently if `$pool` has the `DbPool::Pool` variant. #[macro_export] @@ -337,8 +341,10 @@ fn establish_connection(config: &str) -> BoxFuture LemmyResult { let pool = Pool::builder(manager) .max_size(SETTINGS.database.pool_size) .runtime(Runtime::Tokio1) - // Limit connection age to prevent use of prepared statements that have query plans based on very old statistics + // Limit connection age to prevent use of prepared statements that have query plans based on + // very old statistics .pre_recycle(Hook::sync_fn(|_conn, metrics| { - // Preventing the first recycle can cause an infinite loop when trying to get a new connection from the pool + // Preventing the first recycle can cause an infinite loop when trying to get a new connection + // from the pool let conn_was_used = metrics.recycled.is_some(); if metrics.age() > Duration::from_secs(3 * 24 * 60 * 60) && conn_was_used { Err(HookError::Continue(None)) @@ -508,7 +516,8 @@ pub trait ListFn<'a, T, Args>: Fn(DbConn<'a>, Args) -> ResultFuture<'a, Vec> impl<'a, T, Args, F: Fn(DbConn<'a>, Args) -> ResultFuture<'a, Vec>> ListFn<'a, T, Args> for F {} -/// Allows read and list functions to capture a shared closure that has an inferred return type, which is useful for join logic +/// Allows read and list functions to capture a shared closure that has an inferred return type, +/// which is useful for join logic pub struct Queries { pub read_fn: RF, pub list_fn: LF, diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index e524e9a30..ebea1a5f4 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -150,7 +150,8 @@ fn queries<'a>() -> Queries< query = query.filter(comment_report::comment_id.eq(comment_id)); } - // If viewing all reports, order by newest, but if viewing unresolved only, show the oldest first (FIFO) + // If viewing all reports, order by newest, but if viewing unresolved only, show the oldest + // first (FIFO) if options.unresolved_only { query = query .filter(comment_report::resolved.eq(false)) diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 443512b64..7588943b9 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -238,7 +238,7 @@ fn queries<'a>() -> Queries< ); match listing_type { - ListingType::Subscribed => query = query.filter(is_subscribed), // TODO could be this: and(community_follower::person_id.eq(person_id_join)), + ListingType::Subscribed => query = query.filter(is_subscribed), /* TODO could be this: and(community_follower::person_id.eq(person_id_join)), */ ListingType::Local => { query = query .filter(community::local.eq(true)) @@ -327,7 +327,8 @@ fn queries<'a>() -> Queries< query = query.filter(nlevel(comment::path).le(depth_limit)); - // only order if filtering by a post id, or parent_path. DOS potential otherwise and max_depth + !post_id isn't used anyways (afaik) + // only order if filtering by a post id, or parent_path. DOS potential otherwise and max_depth + // + !post_id isn't used anyways (afaik) if options.post_id.is_some() || options.parent_path.is_some() { // Always order by the parent path first query = query.then_order_by(subpath(comment::path, 0, -1)); diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index 76679df1e..ac60deff9 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -178,7 +178,8 @@ fn queries<'a>() -> Queries< query = query.filter(post::id.eq(post_id)); } - // If viewing all reports, order by newest, but if viewing unresolved only, show the oldest first (FIFO) + // If viewing all reports, order by newest, but if viewing unresolved only, show the oldest + // first (FIFO) if options.unresolved_only { query = query .filter(post_report::resolved.eq(false)) diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 2578dc698..14a9b4f81 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -617,7 +617,8 @@ impl PaginationCursor { } // currently we use a postaggregates struct as the pagination token. -// we only use some of the properties of the post aggregates, depending on which sort type we page by +// we only use some of the properties of the post aggregates, depending on which sort type we page +// by #[derive(Clone)] pub struct PaginationCursorData(PostAggregates); @@ -627,7 +628,8 @@ pub struct PostQuery<'a> { pub sort: Option, pub creator_id: Option, pub community_id: Option, - // if true, the query should be handled as if community_id was not given except adding the literal filter + // if true, the query should be handled as if community_id was not given except adding the + // literal filter pub community_id_just_for_prefetch: bool, pub local_user: Option<&'a LocalUserView>, pub search_term: Option, @@ -649,15 +651,17 @@ impl<'a> PostQuery<'a> { site: &Site, pool: &mut DbPool<'_>, ) -> Result>, Error> { - // first get one page for the most popular community to get an upper bound for the page end for the real query - // the reason this is needed is that when fetching posts for a single community PostgreSQL can optimize - // the query to use an index on e.g. (=, >=, >=, >=) and fetch only LIMIT rows - // but for the followed-communities query it has to query the index on (IN, >=, >=, >=) - // which it currently can't do at all (as of PG 16). see the discussion here: - // https://github.com/LemmyNet/lemmy/issues/2877#issuecomment-1673597190 + // first get one page for the most popular community to get an upper bound for the page end for + // the real query the reason this is needed is that when fetching posts for a single + // community PostgreSQL can optimize the query to use an index on e.g. (=, >=, >=, >=) and + // fetch only LIMIT rows but for the followed-communities query it has to query the index on + // (IN, >=, >=, >=) which it currently can't do at all (as of PG 16). see the discussion + // here: https://github.com/LemmyNet/lemmy/issues/2877#issuecomment-1673597190 // - // the results are correct no matter which community we fetch these for, since it basically covers the "worst case" of the whole page consisting of posts from one community - // but using the largest community decreases the pagination-frame so make the real query more efficient. + // the results are correct no matter which community we fetch these for, since it basically + // covers the "worst case" of the whole page consisting of posts from one community + // but using the largest community decreases the pagination-frame so make the real query more + // efficient. use lemmy_db_schema::schema::{ community_aggregates::dsl::{community_aggregates, community_id, users_active_month}, community_follower::dsl::{ @@ -708,7 +712,8 @@ impl<'a> PostQuery<'a> { ) .await?; // take last element of array. if this query returned less than LIMIT elements, - // the heuristic is invalid since we can't guarantee the full query will return >= LIMIT results (return original query) + // the heuristic is invalid since we can't guarantee the full query will return >= LIMIT results + // (return original query) if (v.len() as i64) < limit { Ok(Some(self.clone())) } else { @@ -1429,7 +1434,8 @@ mod tests { let mut inserted_post_ids = vec![]; let mut inserted_comment_ids = vec![]; - // Create 150 posts with varying non-correlating values for publish date, number of comments, and featured + // Create 150 posts with varying non-correlating values for publish date, number of comments, + // and featured for comments in 0..10 { for _ in 0..15 { let post_form = PostInsertForm::builder() diff --git a/crates/db_views/src/private_message_report_view.rs b/crates/db_views/src/private_message_report_view.rs index a402d0d4f..6011574e6 100644 --- a/crates/db_views/src/private_message_report_view.rs +++ b/crates/db_views/src/private_message_report_view.rs @@ -49,7 +49,8 @@ fn queries<'a>() -> Queries< let list = move |mut conn: DbConn<'a>, options: PrivateMessageReportQuery| async move { let mut query = all_joins(private_message_report::table.into_boxed()); - // If viewing all reports, order by newest, but if viewing unresolved only, show the oldest first (FIFO) + // If viewing all reports, order by newest, but if viewing unresolved only, show the oldest + // first (FIFO) if options.unresolved_only { query = query .filter(private_message_report::resolved.eq(false)) diff --git a/crates/db_views/src/registration_application_view.rs b/crates/db_views/src/registration_application_view.rs index 7346dcd0d..65629d65c 100644 --- a/crates/db_views/src/registration_application_view.rs +++ b/crates/db_views/src/registration_application_view.rs @@ -49,7 +49,8 @@ fn queries<'a>() -> Queries< let list = move |mut conn: DbConn<'a>, options: RegistrationApplicationQuery| async move { let mut query = all_joins(registration_application::table.into_boxed()); - // If viewing all applications, order by newest, but if viewing unresolved only, show the oldest first (FIFO) + // If viewing all applications, order by newest, but if viewing unresolved only, show the oldest + // first (FIFO) if options.unread_only { query = query .filter(registration_application::admin_id.is_null()) diff --git a/crates/db_views/src/structs.rs b/crates/db_views/src/structs.rs index c1facfcee..b37abab37 100644 --- a/crates/db_views/src/structs.rs +++ b/crates/db_views/src/structs.rs @@ -112,9 +112,10 @@ pub struct PostReportView { pub resolver: Option, } -/// currently this is just a wrapper around post id, but should be seen as opaque from the client's perspective -/// stringified since we might want to use arbitrary info later, with a P prepended to prevent ossification -/// (api users love to make assumptions (e.g. parse stuff that looks like numbers as numbers) about apis that aren't part of the spec +/// currently this is just a wrapper around post id, but should be seen as opaque from the client's +/// perspective stringified since we might want to use arbitrary info later, with a P prepended to +/// prevent ossification (api users love to make assumptions (e.g. parse stuff that looks like +/// numbers as numbers) about apis that aren't part of the spec #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(ts_rs::TS))] #[cfg_attr(feature = "full", ts(export))] diff --git a/crates/db_views_actor/src/community_follower_view.rs b/crates/db_views_actor/src/community_follower_view.rs index b2eeda29e..7b942e043 100644 --- a/crates/db_views_actor/src/community_follower_view.rs +++ b/crates/db_views_actor/src/community_follower_view.rs @@ -14,7 +14,8 @@ use lemmy_db_schema::{ }; impl CommunityFollowerView { - /// return a list of local community ids and remote inboxes that at least one user of the given instance has followed + /// return a list of local community ids and remote inboxes that at least one user of the given + /// instance has followed pub async fn get_instance_followed_community_inboxes( pool: &mut DbPool<'_>, instance_id: InstanceId, @@ -22,8 +23,9 @@ impl CommunityFollowerView { ) -> Result, Error> { let conn = &mut get_conn(pool).await?; // In most cases this will fetch the same url many times (the shared inbox url) - // PG will only send a single copy to rust, but it has to scan through all follower rows (same as it was before). - // So on the PG side it would be possible to optimize this further by adding e.g. a new table community_followed_instances (community_id, instance_id) + // PG will only send a single copy to rust, but it has to scan through all follower rows (same + // as it was before). So on the PG side it would be possible to optimize this further by + // adding e.g. a new table community_followed_instances (community_id, instance_id) // that would work for all instances that support fully shared inboxes. // It would be a bit more complicated though to keep it in sync. @@ -31,7 +33,8 @@ impl CommunityFollowerView { .inner_join(community::table) .inner_join(person::table) .filter(person::instance_id.eq(instance_id)) - .filter(community::local) // this should be a no-op since community_followers table only has local-person+remote-community or remote-person+local-community + .filter(community::local) // this should be a no-op since community_followers table only has + // local-person+remote-community or remote-person+local-community .filter(not(person::local)) .filter(community_follower::published.gt(published_since.naive_utc())) .select(( diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index b5c23c6ef..0ff421540 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -154,7 +154,7 @@ fn queries<'a>() -> Queries< if let Some(listing_type) = options.listing_type { query = match listing_type { - ListingType::Subscribed => query.filter(community_follower::pending.is_not_null()), // TODO could be this: and(community_follower::person_id.eq(person_id_join)), + ListingType::Subscribed => query.filter(community_follower::pending.is_not_null()), /* TODO could be this: and(community_follower::person_id.eq(person_id_join)), */ ListingType::Local => query.filter(community::local.eq(true)), _ => query, }; diff --git a/crates/federate/src/lib.rs b/crates/federate/src/lib.rs index fc5bd2387..e6145dad9 100644 --- a/crates/federate/src/lib.rs +++ b/crates/federate/src/lib.rs @@ -119,7 +119,8 @@ async fn start_stop_federation_workers( workers.len(), WORKER_EXIT_TIMEOUT ); - // the cancel futures need to be awaited concurrently for the shutdown processes to be triggered concurrently + // the cancel futures need to be awaited concurrently for the shutdown processes to be triggered + // concurrently futures::future::join_all(workers.into_values().map(util::CancellableTask::cancel)).await; exit_print.await?; Ok(()) @@ -140,7 +141,8 @@ pub fn start_stop_federation_workers_cancellable( }) } -/// every 60s, print the state for every instance. exits if the receiver is done (all senders dropped) +/// every 60s, print the state for every instance. exits if the receiver is done (all senders +/// dropped) async fn receive_print_stats( pool: ActualDbPool, mut receiver: UnboundedReceiver<(String, FederationQueueState)>, @@ -171,7 +173,8 @@ async fn print_stats(pool: &mut DbPool<'_>, stats: &HashMap = Lazy::new(|| { std::env::var("LEMMY_TEST_FAST_FEDERATION") .map(|s| !s.is_empty()) @@ -35,9 +36,10 @@ pub(crate) static LEMMY_TEST_FAST_FEDERATION: Lazy = Lazy::new(|| { /// Recheck for new federation work every n seconds. /// -/// When the queue is processed faster than new activities are added and it reaches the current time with an empty batch, -/// this is the delay the queue waits before it checks if new activities have been added to the sent_activities table. -/// This delay is only applied if no federated activity happens during sending activities of the last batch. +/// When the queue is processed faster than new activities are added and it reaches the current time +/// with an empty batch, this is the delay the queue waits before it checks if new activities have +/// been added to the sent_activities table. This delay is only applied if no federated activity +/// happens during sending activities of the last batch. pub(crate) static WORK_FINISHED_RECHECK_DELAY: Lazy = Lazy::new(|| { if *LEMMY_TEST_FAST_FEDERATION { Duration::from_millis(100) @@ -47,7 +49,8 @@ pub(crate) static WORK_FINISHED_RECHECK_DELAY: Lazy = Lazy::new(|| { }); /// A task that will be run in an infinite loop, unless it is cancelled. -/// If the task exits without being cancelled, an error will be logged and the task will be restarted. +/// If the task exits without being cancelled, an error will be logged and the task will be +/// restarted. pub struct CancellableTask { f: Pin> + Send + 'static>>, } diff --git a/crates/federate/src/worker.rs b/crates/federate/src/worker.rs index f6701a8d1..b2d897522 100644 --- a/crates/federate/src/worker.rs +++ b/crates/federate/src/worker.rs @@ -36,17 +36,22 @@ use tokio::{sync::mpsc::UnboundedSender, time::sleep}; use tokio_util::sync::CancellationToken; use tracing::{debug, info, trace, warn}; -/// Check whether to save state to db every n sends if there's no failures (during failures state is saved after every attempt) -/// This determines the batch size for loop_batch. After a batch ends and SAVE_STATE_EVERY_TIME has passed, the federation_queue_state is updated in the DB. +/// Check whether to save state to db every n sends if there's no failures (during failures state is +/// saved after every attempt) This determines the batch size for loop_batch. After a batch ends and +/// SAVE_STATE_EVERY_TIME has passed, the federation_queue_state is updated in the DB. static CHECK_SAVE_STATE_EVERY_IT: i64 = 100; -/// Save state to db after this time has passed since the last state (so if the server crashes or is SIGKILLed, less than X seconds of activities are resent) +/// Save state to db after this time has passed since the last state (so if the server crashes or is +/// SIGKILLed, less than X seconds of activities are resent) static SAVE_STATE_EVERY_TIME: Duration = Duration::from_secs(60); /// interval with which new additions to community_followers are queried. /// -/// The first time some user on an instance follows a specific remote community (or, more precisely: the first time a (followed_community_id, follower_inbox_url) tuple appears), -/// this delay limits the maximum time until the follow actually results in activities from that community id being sent to that inbox url. -/// This delay currently needs to not be too small because the DB load is currently fairly high because of the current structure of storing inboxes for every person, not having a separate list of shared_inboxes, and the architecture of having every instance queue be fully separate. -/// (see https://github.com/LemmyNet/lemmy/issues/3958) +/// The first time some user on an instance follows a specific remote community (or, more precisely: +/// the first time a (followed_community_id, follower_inbox_url) tuple appears), this delay limits +/// the maximum time until the follow actually results in activities from that community id being +/// sent to that inbox url. This delay currently needs to not be too small because the DB load is +/// currently fairly high because of the current structure of storing inboxes for every person, not +/// having a separate list of shared_inboxes, and the architecture of having every instance queue be +/// fully separate. (see https://github.com/LemmyNet/lemmy/issues/3958) static FOLLOW_ADDITIONS_RECHECK_DELAY: Lazy = Lazy::new(|| { if *LEMMY_TEST_FAST_FEDERATION { chrono::TimeDelta::try_seconds(1).expect("TimeDelta out of bounds") @@ -54,8 +59,9 @@ static FOLLOW_ADDITIONS_RECHECK_DELAY: Lazy = Lazy::new(|| { chrono::TimeDelta::try_minutes(2).expect("TimeDelta out of bounds") } }); -/// The same as FOLLOW_ADDITIONS_RECHECK_DELAY, but triggering when the last person on an instance unfollows a specific remote community. -/// This is expected to happen pretty rarely and updating it in a timely manner is not too important. +/// The same as FOLLOW_ADDITIONS_RECHECK_DELAY, but triggering when the last person on an instance +/// unfollows a specific remote community. This is expected to happen pretty rarely and updating it +/// in a timely manner is not too important. static FOLLOW_REMOVALS_RECHECK_DELAY: Lazy = Lazy::new(|| chrono::TimeDelta::try_hours(1).expect("TimeDelta out of bounds")); pub(crate) struct InstanceWorker { @@ -80,7 +86,8 @@ impl InstanceWorker { pub(crate) async fn init_and_loop( instance: Instance, context: Data, - pool: &mut DbPool<'_>, // in theory there's a ref to the pool in context, but i couldn't get that to work wrt lifetimes + pool: &mut DbPool<'_>, /* in theory there's a ref to the pool in context, but i couldn't get + * that to work wrt lifetimes */ stop: CancellationToken, stats_sender: UnboundedSender<(String, FederationQueueState)>, ) -> Result<(), anyhow::Error> { @@ -101,7 +108,8 @@ impl InstanceWorker { worker.loop_until_stopped(pool).await } /// loop fetch new activities from db and send them to the inboxes of the given instances - /// this worker only returns if (a) there is an internal error or (b) the cancellation token is cancelled (graceful exit) + /// this worker only returns if (a) there is an internal error or (b) the cancellation token is + /// cancelled (graceful exit) pub(crate) async fn loop_until_stopped( &mut self, pool: &mut DbPool<'_>, @@ -152,8 +160,8 @@ impl InstanceWorker { let mut id = if let Some(id) = self.state.last_successful_id { id } else { - // this is the initial creation (instance first seen) of the federation queue for this instance - // skip all past activities: + // this is the initial creation (instance first seen) of the federation queue for this + // instance skip all past activities: self.state.last_successful_id = Some(latest_id); // save here to ensure it's not read as 0 again later if no activities have happened self.save_and_send_state(pool).await?; @@ -281,7 +289,8 @@ impl InstanceWorker { self.site_loaded = true; } if let Some(site) = &self.site { - // Nutomic: Most non-lemmy software wont have a site row. That means it cant handle these activities. So handling it like this is fine. + // Nutomic: Most non-lemmy software wont have a site row. That means it cant handle these + // activities. So handling it like this is fine. inbox_urls.insert(site.inbox_url.inner().clone()); } } @@ -324,7 +333,8 @@ impl InstanceWorker { Ok(()) } - /// get a list of local communities with the remote inboxes on the given instance that cares about them + /// get a list of local communities with the remote inboxes on the given instance that cares about + /// them async fn get_communities( &mut self, pool: &mut DbPool<'_>, @@ -332,7 +342,8 @@ impl InstanceWorker { last_fetch: DateTime, ) -> Result<(HashMap>, DateTime)> { let new_last_fetch = - Utc::now() - chrono::TimeDelta::try_seconds(10).expect("TimeDelta out of bounds"); // update to time before fetch to ensure overlap. subtract 10s to ensure overlap even if published date is not exact + Utc::now() - chrono::TimeDelta::try_seconds(10).expect("TimeDelta out of bounds"); // update to time before fetch to ensure overlap. subtract 10s to ensure overlap even if + // published date is not exact Ok(( CommunityFollowerView::get_instance_followed_community_inboxes(pool, instance_id, last_fetch) .await? diff --git a/crates/utils/src/error.rs b/crates/utils/src/error.rs index 53fba7c9e..324c08ccb 100644 --- a/crates/utils/src/error.rs +++ b/crates/utils/src/error.rs @@ -166,7 +166,8 @@ pub enum LemmyErrorType { CouldntSendWebmention, ContradictingFilters, InstanceBlockAlreadyExists, - /// Thrown when an API call is submitted with more than 1000 array elements, see [[MAX_API_PARAM_ELEMENTS]] + /// Thrown when an API call is submitted with more than 1000 array elements, see + /// [[MAX_API_PARAM_ELEMENTS]] TooManyItems, CommunityHasNoFollowers, BanExpirationInPast, diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index 95c1d0144..1adb3f6cf 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -56,6 +56,7 @@ pub fn spawn_try_task( tracing::warn!("error in spawn: {e}"); } } - .in_current_span(), // this makes sure the inner tracing gets the same context as where spawn was called + .in_current_span(), /* this makes sure the inner tracing gets the same context as where + * spawn was called */ ); } diff --git a/crates/utils/src/rate_limit/rate_limiter.rs b/crates/utils/src/rate_limit/rate_limiter.rs index 3f89aee7e..5f1b6f7f5 100644 --- a/crates/utils/src/rate_limit/rate_limiter.rs +++ b/crates/utils/src/rate_limit/rate_limiter.rs @@ -46,9 +46,10 @@ impl Bucket { fn update(self, now: InstantSecs, config: BucketConfig) -> Self { let secs_since_last_checked = now.secs.saturating_sub(self.last_checked.secs); - // For `secs_since_last_checked` seconds, the amount of tokens increases by `capacity` every `secs_to_refill` seconds. - // The amount of tokens added per second is `capacity / secs_to_refill`. - // The expression below is like `secs_since_last_checked * (capacity / secs_to_refill)` but with precision and non-overflowing multiplication. + // For `secs_since_last_checked` seconds, the amount of tokens increases by `capacity` every + // `secs_to_refill` seconds. The amount of tokens added per second is `capacity / + // secs_to_refill`. The expression below is like `secs_since_last_checked * (capacity / + // secs_to_refill)` but with precision and non-overflowing multiplication. let added_tokens = u64::from(secs_since_last_checked) * u64::from(config.capacity) / u64::from(config.secs_to_refill); @@ -124,8 +125,9 @@ impl MapLevel for Map { ..config }); - // Remove groups that are no longer needed if the hash map's existing allocation has no space for new groups. - // This is done before calling `HashMap::entry` because that immediately allocates just like `HashMap::insert`. + // Remove groups that are no longer needed if the hash map's existing allocation has no space + // for new groups. This is done before calling `HashMap::entry` because that immediately + // allocates just like `HashMap::insert`. if (self.capacity() == self.len()) && !self.contains_key(&addr_part) { self.remove_full_buckets(now, configs); } @@ -219,7 +221,8 @@ impl RateLimitedGroup { if new_bucket.tokens == 0 { // Not enough tokens yet - // Setting `bucket` to `new_bucket` here is useless and would cause the bucket to start over at 0 tokens because of rounding + // Setting `bucket` to `new_bucket` here is useless and would cause the bucket to start over + // at 0 tokens because of rounding false } else { // Consume 1 token @@ -239,10 +242,12 @@ pub struct RateLimitState { /// /// The same thing happens for the first 48 and 56 bits, but with increased capacity. /// - /// This is done because all users can easily switch to any other IPv6 address that has the same first 64 bits. - /// It could be as low as 48 bits for some networks, which is the reason for 48 and 56 bit address groups. + /// This is done because all users can easily switch to any other IPv6 address that has the same + /// first 64 bits. It could be as low as 48 bits for some networks, which is the reason for 48 + /// and 56 bit address groups. ipv6_buckets: Map<[u8; 6], Map>>, - /// This stores a `BucketConfig` for each `ActionType`. `EnumMap` makes it impossible to have a missing `BucketConfig`. + /// This stores a `BucketConfig` for each `ActionType`. `EnumMap` makes it impossible to have a + /// missing `BucketConfig`. bucket_configs: EnumMap, } @@ -339,7 +344,8 @@ mod tests { let mut rate_limiter = RateLimitState::new(bucket_configs); let mut now = InstantSecs::now(); - // Do 1 `Message` and 1 `Post` action for each IP address, and expect the limit to not be reached + // Do 1 `Message` and 1 `Post` action for each IP address, and expect the limit to not be + // reached let ips = [ "123.123.123.123", "1:2:3::", diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index 91a5b37f4..75aa56a88 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -38,7 +38,8 @@ pub struct Settings { /// Whether the site is available over TLS. Needs to be true for federation to work. #[default(true)] pub tls_enabled: bool, - /// Set the URL for opentelemetry exports. If you do not have an opentelemetry collector, do not set this option + /// Set the URL for opentelemetry exports. If you do not have an opentelemetry collector, do not + /// set this option #[default(None)] #[doku(skip)] pub opentelemetry_url: Option, @@ -85,7 +86,8 @@ pub struct PictrsConfig { /// To be removed in 0.20 pub(super) cache_external_link_previews: Option, - /// Specifies how to handle remote images, so that users don't have to connect directly to remote servers. + /// Specifies how to handle remote images, so that users don't have to connect directly to remote + /// servers. #[default(PictrsImageMode::StoreLinkPreviews)] pub(super) image_mode: PictrsImageMode, @@ -107,10 +109,11 @@ pub enum PictrsImageMode { /// This is the default behaviour, and also matches Lemmy 0.18. #[default] StoreLinkPreviews, - /// If enabled, all images from remote domains are rewritten to pass through `/api/v3/image_proxy`, - /// including embedded images in markdown. Images are stored temporarily in pict-rs for caching. - /// This improves privacy as users don't expose their IP to untrusted servers, and decreases load - /// on other servers. However it increases bandwidth use for the local server. + /// If enabled, all images from remote domains are rewritten to pass through + /// `/api/v3/image_proxy`, including embedded images in markdown. Images are stored temporarily + /// in pict-rs for caching. This improves privacy as users don't expose their IP to untrusted + /// servers, and decreases load on other servers. However it increases bandwidth use for the + /// local server. /// /// Requires pict-rs 0.5 ProxyAllImages, diff --git a/crates/utils/src/utils/slurs.rs b/crates/utils/src/utils/slurs.rs index c7c8a88e3..ba94372fa 100644 --- a/crates/utils/src/utils/slurs.rs +++ b/crates/utils/src/utils/slurs.rs @@ -101,7 +101,7 @@ mod test { // These helped with testing // #[test] // fn test_send_email() { - // let result = send_email("not a subject", "test_email@gmail.com", "ur user", "

HI there

"); - // assert!(result.is_ok()); + // let result = send_email("not a subject", "test_email@gmail.com", "ur user", "

HI + // there

"); assert!(result.is_ok()); // } } diff --git a/src/api_routes_http.rs b/src/api_routes_http.rs index 1702ceb2a..2a15b4ca6 100644 --- a/src/api_routes_http.rs +++ b/src/api_routes_http.rs @@ -272,7 +272,8 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { .service( // Handle /user/login separately to add the register() rate limiter // TODO: pretty annoying way to apply rate limits for register and login, we should - // group them under a common path so that rate limit is only applied once (eg under /account). + // group them under a common path so that rate limit is only applied once (eg under + // /account). web::resource("/user/login") .guard(guard::Post()) .wrap(rate_limit.register()) diff --git a/src/lib.rs b/src/lib.rs index 85e2110a6..38e9addd7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,13 +75,14 @@ use url::Url; pub struct CmdArgs { /// Don't run scheduled tasks. /// - /// If you are running multiple Lemmy server processes, you probably want to disable scheduled tasks on - /// all but one of the processes, to avoid running the tasks more often than intended. + /// If you are running multiple Lemmy server processes, you probably want to disable scheduled + /// tasks on all but one of the processes, to avoid running the tasks more often than intended. #[arg(long, default_value_t = false, env = "LEMMY_DISABLE_SCHEDULED_TASKS")] disable_scheduled_tasks: bool, /// Disables the HTTP server. /// - /// This can be used to run a Lemmy server process that only performs scheduled tasks or activity sending. + /// This can be used to run a Lemmy server process that only performs scheduled tasks or activity + /// sending. #[arg(long, default_value_t = false, env = "LEMMY_DISABLE_HTTP_SERVER")] disable_http_server: bool, /// Disable sending outgoing ActivityPub messages. @@ -92,10 +93,11 @@ pub struct CmdArgs { disable_activity_sending: bool, /// The index of this outgoing federation process. /// - /// Defaults to 1/1. If you want to split the federation workload onto n servers, run each server 1≤i≤n with these args: - /// --federate-process-index i --federate-process-count n + /// Defaults to 1/1. If you want to split the federation workload onto n servers, run each server + /// 1≤i≤n with these args: --federate-process-index i --federate-process-count n /// - /// Make you have exactly one server with each `i` running, otherwise federation will randomly send duplicates or nothing. + /// Make you have exactly one server with each `i` running, otherwise federation will randomly + /// send duplicates or nothing. /// /// See https://join-lemmy.org/docs/administration/horizontal_scaling.html for more detail. #[arg(long, default_value_t = 1, env = "LEMMY_FEDERATE_PROCESS_INDEX")] @@ -292,7 +294,9 @@ fn create_http_server( let cors_config = cors_config(&settings); let app = App::new() .wrap(middleware::Logger::new( - // This is the default log format save for the usage of %{r}a over %a to guarantee to record the client's (forwarded) IP and not the last peer address, since the latter is frequently just a reverse proxy + // This is the default log format save for the usage of %{r}a over %a to guarantee to + // record the client's (forwarded) IP and not the last peer address, since the latter is + // frequently just a reverse proxy "%{r}a '%r' %s %b '%{Referer}i' '%{User-Agent}i' %T", )) .wrap(middleware::Compress::default()) @@ -334,7 +338,8 @@ fn cors_config(settings: &Settings) -> Cors { let cors_origin_setting = settings.cors_origin(); match (cors_origin_setting.clone(), cfg!(debug_assertions)) { (Some(origin), false) => { - // Need to call send_wildcard() explicitly, passing this into allowed_origin() results in error + // Need to call send_wildcard() explicitly, passing this into allowed_origin() results in + // error if cors_origin_setting.as_deref() == Some("*") { Cors::default().allow_any_origin().send_wildcard() } else { diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index f7904104f..e591842c6 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -467,10 +467,11 @@ async fn update_instance_software( for instance in instances { let node_info_url = format!("https://{}/nodeinfo/2.0.json", instance.domain); - // The `updated` column is used to check if instances are alive. If it is more than three days - // in the past, no outgoing activities will be sent to that instance. However not every - // Fediverse instance has a valid Nodeinfo endpoint (its not required for Activitypub). That's - // why we always need to mark instances as updated if they are alive. + // The `updated` column is used to check if instances are alive. If it is more than three + // days in the past, no outgoing activities will be sent to that instance. However + // not every Fediverse instance has a valid Nodeinfo endpoint (its not required for + // Activitypub). That's why we always need to mark instances as updated if they are + // alive. let default_form = InstanceForm::builder() .domain(instance.domain.clone()) .updated(Some(naive_now()))