Add diesel_async, get rid of blocking function (#2510)

* Moving settings to Database.

- Moves many settings into the database. Fixes #2285
- Adds a local_site and instance table. Fixes #2365 . Fixes #2368
- Separates SQL update an insert forms, to avoid runtime errors.
- Adds TypedBuilder to all the SQL forms, instead of default.

* Fix weird clippy issue.

* Removing extra lines.

* Some fixes from suggestions.

* Fixing apub tests.

* Using instance creation helper function.

* Move forms to their own line.

* Trying to fix local_site_data, still broken.

* Testing out async

* Testing out async 2

* Fixing federation tests.

* Trying to fix check features 1.

* Starting on adding diesel async. 1/4th done.

* Added async to views and schema.

* Adding some more async

* Compiling now.

* Added diesel async. Fixes #2465

* Running clippy --fix

* Trying to fix cargo test on drone.

* Trying new muslrust.

* Trying a custom dns

* Trying a custom dns 2

* Trying a custom dns 3

* Trying a custom dns 4

* Trying a custom dns 5

* Trying a custom dns 6

* Trying a custom dns 7

* Addressing PR comments.

* Adding check_apub to all verify functions.

* Reverting back drone.

* Fixing merge

* Fix docker images.

* Adding missing discussion_languages.

* Trying to fix federation tests.

* Fix site setup user creation.

* Fix clippy

* Fix clippy 2

* Test api faster

* Try to fix 1

* Try to fix 2

* What are these lines about

* Trying to fix 3

* Moving federation test back to top.

* Remove logging cat.
This commit is contained in:
Dessalines 2022-11-09 05:05:00 -05:00 committed by GitHub
parent ceae0f5993
commit 5d837780f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
239 changed files with 5350 additions and 4898 deletions

View file

@ -10,8 +10,7 @@ steps:
# use minimum supported rust version for most steps
- name: prepare repo
image: clux/muslrust:1.59.0
user: root
image: clux/muslrust:1.64.0
commands:
- git fetch --tags
- git submodule init
@ -34,7 +33,7 @@ steps:
- cargo clippy --workspace --all-features -- -D clippy::unwrap_used
- name: cargo test
image: clux/muslrust:1.59.0
image: clux/muslrust:1.64.0
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
LEMMY_CONFIG_LOCATION: ../../config/config.hjson
@ -46,20 +45,20 @@ steps:
- cargo test --workspace --no-fail-fast --all-features
- name: check defaults.hjson updated
image: clux/muslrust:1.59.0
image: clux/muslrust:1.64.0
commands:
- ./scripts/update_config_defaults.sh config/defaults_current.hjson
- diff config/defaults.hjson config/defaults_current.hjson
- name: check with different features
image: clux/muslrust:1.59.0
image: clux/muslrust:1.64.0
commands:
- cargo install cargo-workspaces
- cargo workspaces exec cargo check --no-default-features
- cargo workspaces exec cargo check --all-features
- name: cargo build
image: clux/muslrust:1.59.0
image: clux/muslrust:1.64.0
commands:
- cargo build
- mv target/x86_64-unknown-linux-musl/debug/lemmy_server target/lemmy_server

897
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -50,9 +50,10 @@ lemmy_api_common = { version = "=0.16.5", path = "crates/api_common" }
lemmy_websocket = { version = "=0.16.5", path = "./crates/websocket" }
lemmy_routes = { version = "=0.16.5", path = "./crates/routes" }
activitypub_federation = "0.2.3"
diesel = "2.0.0"
diesel = "2.0.2"
diesel_migrations = "2.0.0"
serde = { version = "1.0.145", features = ["derive"] }
diesel-async = "0.1.1"
serde = { version = "1.0.147", features = ["derive"] }
actix = "0.13.0"
actix-web = { version = "4.2.1", default-features = false, features = ["macros", "rustls"] }
tracing = "0.1.36"

View file

@ -20,7 +20,7 @@
"eslint": "^8.25.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.0.6",
"lemmy-js-client": "0.17.0-rc.47",
"lemmy-js-client": "0.17.0-rc.48",
"node-fetch": "^2.6.1",
"prettier": "^2.7.1",
"reflect-metadata": "^0.1.13",

View file

@ -31,41 +31,35 @@ killall lemmy_server || true
echo "$PWD"
echo "start alpha"
LEMMY_HOSTNAME=lemmy-alpha:8541 \
LEMMY_CONFIG_LOCATION=./docker/federation/lemmy_alpha.hjson \
LEMMY_DATABASE_URL="${LEMMY_DATABASE_URL}/lemmy_alpha" \
LEMMY_HOSTNAME="lemmy-alpha:8541" \
target/lemmy_server >/tmp/lemmy_alpha.out 2>&1 &
LEMMY_CONFIG_LOCATION=./docker/federation/lemmy_alpha.hjson \
LEMMY_DATABASE_URL="${LEMMY_DATABASE_URL}/lemmy_alpha" \
target/lemmy_server >/tmp/lemmy_alpha.out 2>&1 &
echo "start beta"
LEMMY_HOSTNAME=lemmy-beta:8551 \
LEMMY_CONFIG_LOCATION=./docker/federation/lemmy_beta.hjson \
LEMMY_DATABASE_URL="${LEMMY_DATABASE_URL}/lemmy_beta" \
target/lemmy_server >/tmp/lemmy_beta.out 2>&1 &
LEMMY_CONFIG_LOCATION=./docker/federation/lemmy_beta.hjson \
LEMMY_DATABASE_URL="${LEMMY_DATABASE_URL}/lemmy_beta" \
target/lemmy_server >/tmp/lemmy_beta.out 2>&1 &
echo "start gamma"
LEMMY_HOSTNAME=lemmy-gamma:8561 \
LEMMY_CONFIG_LOCATION=./docker/federation/lemmy_gamma.hjson \
LEMMY_DATABASE_URL="${LEMMY_DATABASE_URL}/lemmy_gamma" \
target/lemmy_server >/tmp/lemmy_gamma.out 2>&1 &
LEMMY_CONFIG_LOCATION=./docker/federation/lemmy_gamma.hjson \
LEMMY_DATABASE_URL="${LEMMY_DATABASE_URL}/lemmy_gamma" \
target/lemmy_server >/tmp/lemmy_gamma.out 2>&1 &
echo "start delta"
# An instance with only an allowlist for beta
LEMMY_HOSTNAME=lemmy-delta:8571 \
LEMMY_CONFIG_LOCATION=./docker/federation/lemmy_delta.hjson \
LEMMY_DATABASE_URL="${LEMMY_DATABASE_URL}/lemmy_delta" \
target/lemmy_server >/tmp/lemmy_delta.out 2>&1 &
LEMMY_CONFIG_LOCATION=./docker/federation/lemmy_delta.hjson \
LEMMY_DATABASE_URL="${LEMMY_DATABASE_URL}/lemmy_delta" \
target/lemmy_server >/tmp/lemmy_delta.out 2>&1 &
echo "start epsilon"
# An instance who has a blocklist, with lemmy-alpha blocked
LEMMY_HOSTNAME=lemmy-epsilon:8581 \
LEMMY_CONFIG_LOCATION=./docker/federation/lemmy_epsilon.hjson \
LEMMY_DATABASE_URL="${LEMMY_DATABASE_URL}/lemmy_epsilon" \
target/lemmy_server >/tmp/lemmy_epsilon.out 2>&1 &
LEMMY_CONFIG_LOCATION=./docker/federation/lemmy_epsilon.hjson \
LEMMY_DATABASE_URL="${LEMMY_DATABASE_URL}/lemmy_epsilon" \
target/lemmy_server >/tmp/lemmy_epsilon.out 2>&1 &
echo "wait for all instances to start"
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8541/api/v3/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8551/api/v3/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8561/api/v3/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8571/api/v3/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8581/api/v3/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-alpha:8541/api/v3/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-beta:8551/api/v3/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-gamma:8561/api/v3/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-delta:8571/api/v3/site')" != "200" ]]; do sleep 1; done
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'lemmy-epsilon:8581/api/v3/site')" != "200" ]]; do sleep 1; done

View file

@ -2373,10 +2373,10 @@ kleur@^3.0.3:
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
lemmy-js-client@0.17.0-rc.47:
version "0.17.0-rc.47"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.47.tgz#6094657d2868767532c0e837a31f9af6273b345b"
integrity sha512-Pc1wyr6sX4Z6LS75NVu46WAXeci5G80+Y9ZBXEAmgM+OZGuOCLUq8lAHRvTwr7M0pj0gxo5yP+i3qPVmTPf+EA==
lemmy-js-client@0.17.0-rc.48:
version "0.17.0-rc.48"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.48.tgz#6085812d4901b7d12b3fca237d8aced7f5210eac"
integrity sha512-Lz8Nzq/kczQtDj6STlbhxoEarFHtTCoWcWBabyPs6X6em/pfK/cnZqx1mMn7EaBSDUVQ+WL8UNFjQiqjhR4kww==
leven@^3.1.0:
version "3.1.0"

View file

@ -23,15 +23,19 @@ lemmy_db_views_actor = { version = "=0.16.5", path = "../db_views_actor", featur
lemmy_api_common = { version = "=0.16.5", path = "../api_common", features = ["full"] }
lemmy_websocket = { version = "=0.16.5", path = "../websocket" }
activitypub_federation = "0.2.3"
diesel = "2.0.0"
diesel = "2.0.2"
bcrypt = "0.13.0"
chrono = { version = "0.4.22", features = ["serde"], default-features = false }
serde_json = { version = "1.0.85", features = ["preserve_order"] }
serde = { version = "1.0.145", features = ["derive"] }
serde_json = { version = "1.0.87", features = ["preserve_order"] }
serde = { version = "1.0.147", features = ["derive"] }
actix-web = { version = "4.2.1", default-features = false }
base64 = "0.13.0"
uuid = { version = "1.1.2", features = ["serde", "v4"] }
async-trait = "0.1.57"
base64 = "0.13.1"
uuid = { version = "1.2.1", features = ["serde", "v4"] }
async-trait = "0.1.58"
captcha = "0.0.9"
anyhow = "1.0.65"
tracing = "0.1.36"
anyhow = "1.0.66"
tracing = "0.1.37"
[dev-dependencies]
serial_test = "0.9.0"
tokio = "1.21.2"

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
comment::{CommentResponse, CreateCommentLike},
utils::{blocking, check_community_ban, check_downvotes_enabled, get_local_user_view_from_jwt},
utils::{check_community_ban, check_downvotes_enabled, get_local_user_view_from_jwt},
};
use lemmy_apub::{
fetcher::post_or_comment::PostOrComment,
@ -36,7 +36,7 @@ impl Perform for CreateCommentLike {
websocket_id: Option<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
let data: &CreateCommentLike = self;
let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_site = LocalSite::read(context.pool()).await?;
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
@ -46,10 +46,7 @@ impl Perform for CreateCommentLike {
check_downvotes_enabled(data.score, &local_site)?;
let comment_id = data.comment_id;
let orig_comment = blocking(context.pool(), move |conn| {
CommentView::read(conn, comment_id, None)
})
.await??;
let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
check_community_ban(
local_user_view.person.id,
@ -59,17 +56,10 @@ impl Perform for CreateCommentLike {
.await?;
// Add parent poster or commenter to recipients
let comment_reply = blocking(context.pool(), move |conn| {
CommentReply::read_by_comment(conn, comment_id)
})
.await?;
let comment_reply = CommentReply::read_by_comment(context.pool(), comment_id).await;
if let Ok(reply) = comment_reply {
let recipient_id = reply.recipient_id;
if let Ok(local_recipient) = blocking(context.pool(), move |conn| {
LocalUserView::read_person(conn, recipient_id)
})
.await?
{
if let Ok(local_recipient) = LocalUserView::read_person(context.pool(), recipient_id).await {
recipient_ids.push(local_recipient.local_user.id);
}
}
@ -83,10 +73,8 @@ impl Perform for CreateCommentLike {
// Remove any likes first
let person_id = local_user_view.person.id;
blocking(context.pool(), move |conn| {
CommentLike::remove(conn, person_id, comment_id)
})
.await??;
CommentLike::remove(context.pool(), person_id, comment_id).await?;
// Only add the like if the score isnt 0
let comment = orig_comment.comment;
@ -94,9 +82,8 @@ impl Perform for CreateCommentLike {
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
if do_add {
let like_form2 = like_form.clone();
let like = move |conn: &mut _| CommentLike::like(conn, &like_form2);
blocking(context.pool(), like)
.await?
CommentLike::like(context.pool(), &like_form2)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
Vote::send(

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
comment::{CommentResponse, SaveComment},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_schema::{
source::comment::{CommentSaved, CommentSavedForm},
@ -32,23 +32,18 @@ impl Perform for SaveComment {
};
if data.save {
let save_comment = move |conn: &mut _| CommentSaved::save(conn, &comment_saved_form);
blocking(context.pool(), save_comment)
.await?
CommentSaved::save(context.pool(), &comment_saved_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
} else {
let unsave_comment = move |conn: &mut _| CommentSaved::unsave(conn, &comment_saved_form);
blocking(context.pool(), unsave_comment)
.await?
CommentSaved::unsave(context.pool(), &comment_saved_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
}
let comment_id = data.comment_id;
let person_id = local_user_view.person.id;
let comment_view = blocking(context.pool(), move |conn| {
CommentView::read(conn, comment_id, Some(person_id))
})
.await??;
let comment_view = CommentView::read(context.pool(), comment_id, Some(person_id)).await?;
Ok(CommentResponse {
comment_view,

View file

@ -3,7 +3,7 @@ use activitypub_federation::core::object_id::ObjectId;
use actix_web::web::Data;
use lemmy_api_common::{
comment::{CommentReportResponse, CreateCommentReport},
utils::{blocking, check_community_ban, get_local_user_view_from_jwt},
utils::{check_community_ban, get_local_user_view_from_jwt},
};
use lemmy_apub::protocol::activities::community::report::Report;
use lemmy_db_schema::{
@ -31,17 +31,14 @@ impl Perform for CreateCommentReport {
let data: &CreateCommentReport = self;
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_site = LocalSite::read(context.pool()).await?;
let reason = self.reason.trim();
check_report_reason(reason, &local_site)?;
let person_id = local_user_view.person.id;
let comment_id = data.comment_id;
let comment_view = blocking(context.pool(), move |conn| {
CommentView::read(conn, comment_id, None)
})
.await??;
let comment_view = CommentView::read(context.pool(), comment_id, None).await?;
check_community_ban(person_id, comment_view.community.id, context.pool()).await?;
@ -52,16 +49,11 @@ impl Perform for CreateCommentReport {
reason: reason.to_owned(),
};
let report = blocking(context.pool(), move |conn| {
CommentReport::report(conn, &report_form)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
let report = CommentReport::report(context.pool(), &report_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
let comment_report_view = blocking(context.pool(), move |conn| {
CommentReportView::read(conn, report.id, person_id)
})
.await??;
let comment_report_view = CommentReportView::read(context.pool(), report.id, person_id).await?;
let res = CommentReportResponse {
comment_report_view,

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
comment::{ListCommentReports, ListCommentReportsResponse},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_views::comment_report_view::CommentReportQuery;
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -31,19 +31,17 @@ impl Perform for ListCommentReports {
let page = data.page;
let limit = data.limit;
let comment_reports = blocking(context.pool(), move |conn| {
CommentReportQuery::builder()
.conn(conn)
.my_person_id(person_id)
.admin(admin)
.community_id(community_id)
.unresolved_only(unresolved_only)
.page(page)
.limit(limit)
.build()
.list()
})
.await??;
let comment_reports = CommentReportQuery::builder()
.pool(context.pool())
.my_person_id(person_id)
.admin(admin)
.community_id(community_id)
.unresolved_only(unresolved_only)
.page(page)
.limit(limit)
.build()
.list()
.await?;
let res = ListCommentReportsResponse { comment_reports };

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
comment::{CommentReportResponse, ResolveCommentReport},
utils::{blocking, get_local_user_view_from_jwt, is_mod_or_admin},
utils::{get_local_user_view_from_jwt, is_mod_or_admin},
};
use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
use lemmy_db_views::structs::CommentReportView;
@ -26,32 +26,23 @@ impl Perform for ResolveCommentReport {
let report_id = data.report_id;
let person_id = local_user_view.person.id;
let report = blocking(context.pool(), move |conn| {
CommentReportView::read(conn, report_id, person_id)
})
.await??;
let report = CommentReportView::read(context.pool(), report_id, person_id).await?;
let person_id = local_user_view.person.id;
is_mod_or_admin(context.pool(), person_id, report.community.id).await?;
let resolved = data.resolved;
let resolve_fun = move |conn: &mut _| {
if resolved {
CommentReport::resolve(conn, report_id, person_id)
} else {
CommentReport::unresolve(conn, report_id, person_id)
}
};
blocking(context.pool(), resolve_fun)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
if data.resolved {
CommentReport::resolve(context.pool(), report_id, person_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
} else {
CommentReport::unresolve(context.pool(), report_id, person_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
}
let report_id = data.report_id;
let comment_report_view = blocking(context.pool(), move |conn| {
CommentReportView::read(conn, report_id, person_id)
})
.await??;
let comment_report_view = CommentReportView::read(context.pool(), report_id, person_id).await?;
let res = CommentReportResponse {
comment_report_view,

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
community::{AddModToCommunity, AddModToCommunityResponse},
utils::{blocking, get_local_user_view_from_jwt, is_mod_or_admin},
utils::{get_local_user_view_from_jwt, is_mod_or_admin},
};
use lemmy_apub::{
objects::{community::ApubCommunity, person::ApubPerson},
@ -38,10 +38,7 @@ impl Perform for AddModToCommunity {
// Verify that only mods or admins can add mod
is_mod_or_admin(context.pool(), local_user_view.person.id, community_id).await?;
let community = blocking(context.pool(), move |conn| {
Community::read(conn, community_id)
})
.await??;
let community = Community::read(context.pool(), community_id).await?;
if local_user_view.person.admin && !community.local {
return Err(LemmyError::from_message("not_a_moderator"));
}
@ -52,14 +49,12 @@ impl Perform for AddModToCommunity {
person_id: data.person_id,
};
if data.added {
let join = move |conn: &mut _| CommunityModerator::join(conn, &community_moderator_form);
blocking(context.pool(), join)
.await?
CommunityModerator::join(context.pool(), &community_moderator_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
} else {
let leave = move |conn: &mut _| CommunityModerator::leave(conn, &community_moderator_form);
blocking(context.pool(), leave)
.await?
CommunityModerator::leave(context.pool(), &community_moderator_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
}
@ -70,18 +65,12 @@ impl Perform for AddModToCommunity {
community_id: data.community_id,
removed: Some(!data.added),
};
blocking(context.pool(), move |conn| {
ModAddCommunity::create(conn, &form)
})
.await??;
ModAddCommunity::create(context.pool(), &form).await?;
// Send to federated instances
let updated_mod_id = data.person_id;
let updated_mod: ApubPerson = blocking(context.pool(), move |conn| {
Person::read(conn, updated_mod_id)
})
.await??
.into();
let updated_mod: ApubPerson = Person::read(context.pool(), updated_mod_id).await?.into();
let community: ApubCommunity = community.into();
if data.added {
AddMod::send(
@ -104,10 +93,7 @@ impl Perform for AddModToCommunity {
// Note: in case a remote mod is added, this returns the old moderators list, it will only get
// updated once we receive an activity from the community (like `Announce/Add/Moderator`)
let community_id = data.community_id;
let moderators = blocking(context.pool(), move |conn| {
CommunityModeratorView::for_community(conn, community_id)
})
.await??;
let moderators = CommunityModeratorView::for_community(context.pool(), community_id).await?;
let res = AddModToCommunityResponse { moderators };
context.chat_server().do_send(SendCommunityRoomMessage {

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
community::{BanFromCommunity, BanFromCommunityResponse},
utils::{blocking, get_local_user_view_from_jwt, is_mod_or_admin, remove_user_data_in_community},
utils::{get_local_user_view_from_jwt, is_mod_or_admin, remove_user_data_in_community},
};
use lemmy_apub::{
activities::block::SiteOrCommunity,
@ -55,21 +55,12 @@ impl Perform for BanFromCommunity {
expires: Some(expires),
};
let community: ApubCommunity = blocking(context.pool(), move |conn: &mut _| {
Community::read(conn, community_id)
})
.await??
.into();
let banned_person: ApubPerson = blocking(context.pool(), move |conn: &mut _| {
Person::read(conn, banned_person_id)
})
.await??
.into();
let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
let banned_person: ApubPerson = Person::read(context.pool(), banned_person_id).await?.into();
if data.ban {
let ban = move |conn: &mut _| CommunityPersonBan::ban(conn, &community_user_ban_form);
blocking(context.pool(), ban)
.await?
CommunityPersonBan::ban(context.pool(), &community_user_ban_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?;
// Also unsubscribe them from the community, if they are subscribed
@ -78,11 +69,10 @@ impl Perform for BanFromCommunity {
person_id: banned_person_id,
pending: false,
};
blocking(context.pool(), move |conn: &mut _| {
CommunityFollower::unfollow(conn, &community_follower_form)
})
.await?
.ok();
CommunityFollower::unfollow(context.pool(), &community_follower_form)
.await
.ok();
BlockUser::send(
&SiteOrCommunity::Community(community),
@ -95,9 +85,8 @@ impl Perform for BanFromCommunity {
)
.await?;
} else {
let unban = move |conn: &mut _| CommunityPersonBan::unban(conn, &community_user_ban_form);
blocking(context.pool(), unban)
.await?
CommunityPersonBan::unban(context.pool(), &community_user_ban_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?;
UndoBlockUser::send(
&SiteOrCommunity::Community(community),
@ -123,16 +112,11 @@ impl Perform for BanFromCommunity {
banned: Some(data.ban),
expires,
};
blocking(context.pool(), move |conn| {
ModBanFromCommunity::create(conn, &form)
})
.await??;
ModBanFromCommunity::create(context.pool(), &form).await?;
let person_id = data.person_id;
let person_view = blocking(context.pool(), move |conn| {
PersonViewSafe::read(conn, person_id)
})
.await??;
let person_view = PersonViewSafe::read(context.pool(), person_id).await?;
let res = BanFromCommunityResponse {
person_view,

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
community::{BlockCommunity, BlockCommunityResponse},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_apub::protocol::activities::following::undo_follow::UndoFollowCommunity;
use lemmy_db_schema::{
@ -38,9 +38,8 @@ impl Perform for BlockCommunity {
};
if data.block {
let block = move |conn: &mut _| CommunityBlock::block(conn, &community_block_form);
blocking(context.pool(), block)
.await?
CommunityBlock::block(context.pool(), &community_block_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?;
// Also, unfollow the community, and send a federated unfollow
@ -49,27 +48,19 @@ impl Perform for BlockCommunity {
person_id,
pending: false,
};
blocking(context.pool(), move |conn: &mut _| {
CommunityFollower::unfollow(conn, &community_follower_form)
})
.await?
.ok();
let community = blocking(context.pool(), move |conn| {
Community::read(conn, community_id)
})
.await??;
CommunityFollower::unfollow(context.pool(), &community_follower_form)
.await
.ok();
let community = Community::read(context.pool(), community_id).await?;
UndoFollowCommunity::send(&local_user_view.person.into(), &community.into(), context).await?;
} else {
let unblock = move |conn: &mut _| CommunityBlock::unblock(conn, &community_block_form);
blocking(context.pool(), unblock)
.await?
CommunityBlock::unblock(context.pool(), &community_block_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?;
}
let community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, Some(person_id))
})
.await??;
let community_view = CommunityView::read(context.pool(), community_id, Some(person_id)).await?;
Ok(BlockCommunityResponse {
blocked: data.block,

View file

@ -2,12 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
community::{CommunityResponse, FollowCommunity},
utils::{
blocking,
check_community_ban,
check_community_deleted_or_removed,
get_local_user_view_from_jwt,
},
utils::{check_community_ban, check_community_deleted_or_removed, get_local_user_view_from_jwt},
};
use lemmy_apub::{
objects::community::ApubCommunity,
@ -39,11 +34,7 @@ impl Perform for FollowCommunity {
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let community_id = data.community_id;
let community: ApubCommunity = blocking(context.pool(), move |conn| {
Community::read(conn, community_id)
})
.await??
.into();
let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
let community_follower_form = CommunityFollowerForm {
community_id: data.community_id,
person_id: local_user_view.person.id,
@ -55,15 +46,12 @@ impl Perform for FollowCommunity {
check_community_ban(local_user_view.person.id, community_id, context.pool()).await?;
check_community_deleted_or_removed(community_id, context.pool()).await?;
let follow = move |conn: &mut _| CommunityFollower::follow(conn, &community_follower_form);
blocking(context.pool(), follow)
.await?
CommunityFollower::follow(context.pool(), &community_follower_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
} else {
let unfollow =
move |conn: &mut _| CommunityFollower::unfollow(conn, &community_follower_form);
blocking(context.pool(), unfollow)
.await?
CommunityFollower::unfollow(context.pool(), &community_follower_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
}
} else if data.follow {
@ -74,19 +62,14 @@ impl Perform for FollowCommunity {
} else {
UndoFollowCommunity::send(&local_user_view.person.clone().into(), &community, context)
.await?;
let unfollow =
move |conn: &mut _| CommunityFollower::unfollow(conn, &community_follower_form);
blocking(context.pool(), unfollow)
.await?
CommunityFollower::unfollow(context.pool(), &community_follower_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
}
let community_id = data.community_id;
let person_id = local_user_view.person.id;
let community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, Some(person_id))
})
.await??;
let community_view = CommunityView::read(context.pool(), community_id, Some(person_id)).await?;
Ok(Self::Response { community_view })
}

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
community::{CommunityResponse, HideCommunity},
utils::{blocking, get_local_user_view_from_jwt, is_admin},
utils::{get_local_user_view_from_jwt, is_admin},
};
use lemmy_apub::protocol::activities::community::update::UpdateCommunity;
use lemmy_db_schema::{
@ -44,16 +44,11 @@ impl Perform for HideCommunity {
};
let community_id = data.community_id;
let updated_community = blocking(context.pool(), move |conn| {
Community::update(conn, community_id, &community_form)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community_hidden_status"))?;
let updated_community = Community::update(context.pool(), community_id, &community_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community_hidden_status"))?;
blocking(context.pool(), move |conn| {
ModHideCommunity::create(conn, &mod_hide_community_form)
})
.await??;
ModHideCommunity::create(context.pool(), &mod_hide_community_form).await?;
UpdateCommunity::send(
updated_community.into(),

View file

@ -3,7 +3,7 @@ use actix_web::web::Data;
use anyhow::Context;
use lemmy_api_common::{
community::{GetCommunityResponse, TransferCommunity},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_schema::{
source::{
@ -32,14 +32,12 @@ impl Perform for TransferCommunity {
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let admins = blocking(context.pool(), PersonViewSafe::admins).await??;
let admins = PersonViewSafe::admins(context.pool()).await?;
// Fetch the community mods
let community_id = data.community_id;
let mut community_mods = blocking(context.pool(), move |conn| {
CommunityModeratorView::for_community(conn, community_id)
})
.await??;
let mut community_mods =
CommunityModeratorView::for_community(context.pool(), community_id).await?;
// Make sure transferrer is either the top community mod, or an admin
if local_user_view.person.id != community_mods[0].moderator.id
@ -62,10 +60,8 @@ impl Perform for TransferCommunity {
// Delete all the mods
let community_id = data.community_id;
blocking(context.pool(), move |conn| {
CommunityModerator::delete_for_community(conn, community_id)
})
.await??;
CommunityModerator::delete_for_community(context.pool(), community_id).await?;
// TODO: this should probably be a bulk operation
// Re-add the mods, in the new order
@ -75,9 +71,8 @@ impl Perform for TransferCommunity {
person_id: cmod.moderator.id,
};
let join = move |conn: &mut _| CommunityModerator::join(conn, &community_moderator_form);
blocking(context.pool(), join)
.await?
CommunityModerator::join(context.pool(), &community_moderator_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
}
@ -88,25 +83,19 @@ impl Perform for TransferCommunity {
community_id: data.community_id,
removed: Some(false),
};
blocking(context.pool(), move |conn| {
ModTransferCommunity::create(conn, &form)
})
.await??;
ModTransferCommunity::create(context.pool(), &form).await?;
let community_id = data.community_id;
let person_id = local_user_view.person.id;
let community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, Some(person_id))
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
let community_view = CommunityView::read(context.pool(), community_id, Some(person_id))
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
let community_id = data.community_id;
let moderators = blocking(context.pool(), move |conn| {
CommunityModeratorView::for_community(conn, community_id)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
let moderators = CommunityModeratorView::for_community(context.pool(), community_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
// Return the jwt
Ok(GetCommunityResponse {

View file

@ -253,17 +253,19 @@ mod tests {
secret::Secret,
},
traits::Crud,
utils::establish_unpooled_connection,
utils::build_db_pool_for_tests,
};
use lemmy_utils::{claims::Claims, settings::SETTINGS};
use serial_test::serial;
#[test]
fn test_should_not_validate_user_token_after_password_change() {
let conn = &mut establish_unpooled_connection();
let secret = Secret::init(conn).unwrap();
#[tokio::test]
#[serial]
async fn test_should_not_validate_user_token_after_password_change() {
let pool = &build_db_pool_for_tests().await;
let secret = Secret::init(pool).await.unwrap();
let settings = &SETTINGS.to_owned();
let inserted_instance = Instance::create(conn, "my_domain.tld").unwrap();
let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
let new_person = PersonInsertForm::builder()
.name("Gerry9812".into())
@ -271,14 +273,14 @@ mod tests {
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(conn, &new_person).unwrap();
let inserted_person = Person::create(pool, &new_person).await.unwrap();
let local_user_form = LocalUserInsertForm::builder()
.person_id(inserted_person.id)
.password_encrypted("123456".to_string())
.build();
let inserted_local_user = LocalUser::create(conn, &local_user_form).unwrap();
let inserted_local_user = LocalUser::create(pool, &local_user_form).await.unwrap();
let jwt = Claims::jwt(
inserted_local_user.id.0,
@ -292,11 +294,13 @@ mod tests {
// The check should fail, since the validator time is now newer than the jwt issue time
let updated_local_user =
LocalUser::update_password(conn, inserted_local_user.id, "password111").unwrap();
LocalUser::update_password(pool, inserted_local_user.id, "password111")
.await
.unwrap();
let check_after = check_validator_time(&updated_local_user.validator_time, &claims);
assert!(check_after.is_err());
let num_deleted = Person::delete(conn, inserted_person.id).unwrap();
let num_deleted = Person::delete(pool, inserted_person.id).await.unwrap();
assert_eq!(1, num_deleted);
}
}

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{AddAdmin, AddAdminResponse},
utils::{blocking, get_local_user_view_from_jwt, is_admin},
utils::{get_local_user_view_from_jwt, is_admin},
};
use lemmy_db_schema::{
source::{
@ -34,14 +34,12 @@ impl Perform for AddAdmin {
let added = data.added;
let added_person_id = data.person_id;
let added_admin = blocking(context.pool(), move |conn| {
Person::update(
conn,
added_person_id,
&PersonUpdateForm::builder().admin(Some(added)).build(),
)
})
.await?
let added_admin = Person::update(
context.pool(),
added_person_id,
&PersonUpdateForm::builder().admin(Some(added)).build(),
)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?;
// Mod tables
@ -51,9 +49,9 @@ impl Perform for AddAdmin {
removed: Some(!data.added),
};
blocking(context.pool(), move |conn| ModAdd::create(conn, &form)).await??;
ModAdd::create(context.pool(), &form).await?;
let admins = blocking(context.pool(), PersonViewSafe::admins).await??;
let admins = PersonViewSafe::admins(context.pool()).await?;
let res = AddAdminResponse { admins };

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{BanPerson, BanPersonResponse},
utils::{blocking, get_local_user_view_from_jwt, is_admin, remove_user_data},
utils::{get_local_user_view_from_jwt, is_admin, remove_user_data},
};
use lemmy_apub::{
activities::block::SiteOrCommunity,
@ -41,17 +41,15 @@ impl Perform for BanPerson {
let banned_person_id = data.person_id;
let expires = data.expires.map(naive_from_unix);
let person = blocking(context.pool(), move |conn| {
Person::update(
conn,
banned_person_id,
&PersonUpdateForm::builder()
.banned(Some(ban))
.ban_expires(Some(expires))
.build(),
)
})
.await?
let person = Person::update(
context.pool(),
banned_person_id,
&PersonUpdateForm::builder()
.banned(Some(ban))
.ban_expires(Some(expires))
.build(),
)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?;
// Remove their data if that's desired
@ -75,20 +73,12 @@ impl Perform for BanPerson {
expires,
};
blocking(context.pool(), move |conn| ModBan::create(conn, &form)).await??;
ModBan::create(context.pool(), &form).await?;
let person_id = data.person_id;
let person_view = blocking(context.pool(), move |conn| {
PersonViewSafe::read(conn, person_id)
})
.await??;
let person_view = PersonViewSafe::read(context.pool(), person_id).await?;
let site = SiteOrCommunity::Site(
blocking(context.pool(), SiteView::read_local)
.await??
.site
.into(),
);
let site = SiteOrCommunity::Site(SiteView::read_local(context.pool()).await?.site.into());
// if the action affects a local user, federate to other instances
if person.local {
if ban {

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{BlockPerson, BlockPersonResponse},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_schema::{
source::person_block::{PersonBlock, PersonBlockForm},
@ -39,24 +39,19 @@ impl Perform for BlockPerson {
target_id,
};
let target_person_view = blocking(context.pool(), move |conn| {
PersonViewSafe::read(conn, target_id)
})
.await??;
let target_person_view = PersonViewSafe::read(context.pool(), target_id).await?;
if target_person_view.person.admin {
return Err(LemmyError::from_message("cant_block_admin"));
}
if data.block {
let block = move |conn: &mut _| PersonBlock::block(conn, &person_block_form);
blocking(context.pool(), block)
.await?
PersonBlock::block(context.pool(), &person_block_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?;
} else {
let unblock = move |conn: &mut _| PersonBlock::unblock(conn, &person_block_form);
blocking(context.pool(), unblock)
.await?
PersonBlock::unblock(context.pool(), &person_block_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?;
}

View file

@ -3,7 +3,7 @@ use actix_web::web::Data;
use bcrypt::verify;
use lemmy_api_common::{
person::{ChangePassword, LoginResponse},
utils::{blocking, get_local_user_view_from_jwt, password_length_check},
utils::{get_local_user_view_from_jwt, password_length_check},
};
use lemmy_db_schema::source::local_user::LocalUser;
use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
@ -42,10 +42,8 @@ impl Perform for ChangePassword {
let local_user_id = local_user_view.local_user.id;
let new_password = data.new_password.to_owned();
let updated_local_user = blocking(context.pool(), move |conn| {
LocalUser::update_password(conn, local_user_id, &new_password)
})
.await??;
let updated_local_user =
LocalUser::update_password(context.pool(), local_user_id, &new_password).await?;
// Return the jwt
Ok(LoginResponse {

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{LoginResponse, PasswordChangeAfterReset},
utils::{blocking, password_length_check},
utils::password_length_check,
};
use lemmy_db_schema::source::{
local_user::LocalUser,
@ -25,10 +25,9 @@ impl Perform for PasswordChangeAfterReset {
// Fetch the user_id from the token
let token = data.token.clone();
let local_user_id = blocking(context.pool(), move |conn| {
PasswordResetRequest::read_from_token(conn, &token).map(|p| p.local_user_id)
})
.await??;
let local_user_id = PasswordResetRequest::read_from_token(context.pool(), &token)
.await
.map(|p| p.local_user_id)?;
password_length_check(&data.password)?;
@ -39,11 +38,9 @@ impl Perform for PasswordChangeAfterReset {
// Update the user with the new password
let password = data.password.clone();
let updated_local_user = blocking(context.pool(), move |conn| {
LocalUser::update_password(conn, local_user_id, &password)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?;
let updated_local_user = LocalUser::update_password(context.pool(), local_user_id, &password)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?;
// Return the jwt
Ok(LoginResponse {

View file

@ -2,10 +2,7 @@ use crate::{captcha_as_wav_base64, Perform};
use actix_web::web::Data;
use captcha::{gen, Difficulty};
use chrono::Duration;
use lemmy_api_common::{
person::{CaptchaResponse, GetCaptcha, GetCaptchaResponse},
utils::blocking,
};
use lemmy_api_common::person::{CaptchaResponse, GetCaptcha, GetCaptchaResponse};
use lemmy_db_schema::{source::local_site::LocalSite, utils::naive_now};
use lemmy_utils::{error::LemmyError, ConnectionId};
use lemmy_websocket::{messages::CaptchaItem, LemmyContext};
@ -20,7 +17,7 @@ impl Perform for GetCaptcha {
context: &Data<LemmyContext>,
_websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_site = LocalSite::read(context.pool()).await?;
if !local_site.captcha_enabled {
return Ok(GetCaptchaResponse { ok: None });

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{BannedPersonsResponse, GetBannedPersons},
utils::{blocking, get_local_user_view_from_jwt, is_admin},
utils::{get_local_user_view_from_jwt, is_admin},
};
use lemmy_db_views_actor::structs::PersonViewSafe;
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -24,7 +24,7 @@ impl Perform for GetBannedPersons {
// Make sure user is an admin
is_admin(&local_user_view)?;
let banned = blocking(context.pool(), PersonViewSafe::banned).await??;
let banned = PersonViewSafe::banned(context.pool()).await?;
let res = Self::Response { banned };

View file

@ -3,7 +3,7 @@ use actix_web::web::Data;
use bcrypt::verify;
use lemmy_api_common::{
person::{Login, LoginResponse},
utils::{blocking, check_registration_application, check_user_valid},
utils::{check_registration_application, check_user_valid},
};
use lemmy_db_schema::source::local_site::LocalSite;
use lemmy_db_views::structs::LocalUserView;
@ -22,15 +22,13 @@ impl Perform for Login {
) -> Result<LoginResponse, LemmyError> {
let data: &Login = self;
let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_site = LocalSite::read(context.pool()).await?;
// Fetch that username / email
let username_or_email = data.username_or_email.clone();
let local_user_view = blocking(context.pool(), move |conn| {
LocalUserView::find_by_email_or_name(conn, &username_or_email)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;
let local_user_view = LocalUserView::find_by_email_or_name(context.pool(), &username_or_email)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;
// Verify the password
let valid: bool = verify(

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{GetPersonMentions, GetPersonMentionsResponse},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_views_actor::person_mention_view::PersonMentionQuery;
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -29,20 +29,18 @@ impl Perform for GetPersonMentions {
let person_id = Some(local_user_view.person.id);
let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
let mentions = blocking(context.pool(), move |conn| {
PersonMentionQuery::builder()
.conn(conn)
.recipient_id(person_id)
.my_person_id(person_id)
.sort(sort)
.unread_only(unread_only)
.show_bot_accounts(show_bot_accounts)
.page(page)
.limit(limit)
.build()
.list()
})
.await??;
let mentions = PersonMentionQuery::builder()
.pool(context.pool())
.recipient_id(person_id)
.my_person_id(person_id)
.sort(sort)
.unread_only(unread_only)
.show_bot_accounts(show_bot_accounts)
.page(page)
.limit(limit)
.build()
.list()
.await?;
Ok(GetPersonMentionsResponse { mentions })
}

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{GetReplies, GetRepliesResponse},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_views_actor::comment_reply_view::CommentReplyQuery;
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -29,20 +29,18 @@ impl Perform for GetReplies {
let person_id = Some(local_user_view.person.id);
let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
let replies = blocking(context.pool(), move |conn| {
CommentReplyQuery::builder()
.conn(conn)
.recipient_id(person_id)
.my_person_id(person_id)
.sort(sort)
.unread_only(unread_only)
.show_bot_accounts(show_bot_accounts)
.page(page)
.limit(limit)
.build()
.list()
})
.await??;
let replies = CommentReplyQuery::builder()
.pool(context.pool())
.recipient_id(person_id)
.my_person_id(person_id)
.sort(sort)
.unread_only(unread_only)
.show_bot_accounts(show_bot_accounts)
.page(page)
.limit(limit)
.build()
.list()
.await?;
Ok(GetRepliesResponse { replies })
}

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{GetRepliesResponse, MarkAllAsRead},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_schema::source::{
comment_reply::CommentReply,
@ -28,25 +28,19 @@ impl Perform for MarkAllAsRead {
let person_id = local_user_view.person.id;
// Mark all comment_replies as read
blocking(context.pool(), move |conn| {
CommentReply::mark_all_as_read(conn, person_id)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
CommentReply::mark_all_as_read(context.pool(), person_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
// Mark all user mentions as read
blocking(context.pool(), move |conn| {
PersonMention::mark_all_as_read(conn, person_id)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
PersonMention::mark_all_as_read(context.pool(), person_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
// Mark all private_messages as read
blocking(context.pool(), move |conn| {
PrivateMessage::mark_all_as_read(conn, person_id)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
PrivateMessage::mark_all_as_read(context.pool(), person_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
Ok(GetRepliesResponse { replies: vec![] })
}

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{MarkPersonMentionAsRead, PersonMentionResponse},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_schema::{
source::person_mention::{PersonMention, PersonMentionUpdateForm},
@ -27,10 +27,7 @@ impl Perform for MarkPersonMentionAsRead {
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let person_mention_id = data.person_mention_id;
let read_person_mention = blocking(context.pool(), move |conn| {
PersonMention::read(conn, person_mention_id)
})
.await??;
let read_person_mention = PersonMention::read(context.pool(), person_mention_id).await?;
if local_user_view.person.id != read_person_mention.recipient_id {
return Err(LemmyError::from_message("couldnt_update_comment"));
@ -38,18 +35,18 @@ impl Perform for MarkPersonMentionAsRead {
let person_mention_id = read_person_mention.id;
let read = Some(data.read);
blocking(context.pool(), move |conn| {
PersonMention::update(conn, person_mention_id, &PersonMentionUpdateForm { read })
})
.await?
PersonMention::update(
context.pool(),
person_mention_id,
&PersonMentionUpdateForm { read },
)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
let person_mention_id = read_person_mention.id;
let person_id = local_user_view.person.id;
let person_mention_view = blocking(context.pool(), move |conn| {
PersonMentionView::read(conn, person_mention_id, Some(person_id))
})
.await??;
let person_mention_view =
PersonMentionView::read(context.pool(), person_mention_id, Some(person_id)).await?;
Ok(PersonMentionResponse {
person_mention_view,

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{CommentReplyResponse, MarkCommentReplyAsRead},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_schema::{
source::comment_reply::{CommentReply, CommentReplyUpdateForm},
@ -27,10 +27,7 @@ impl Perform for MarkCommentReplyAsRead {
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let comment_reply_id = data.comment_reply_id;
let read_comment_reply = blocking(context.pool(), move |conn| {
CommentReply::read(conn, comment_reply_id)
})
.await??;
let read_comment_reply = CommentReply::read(context.pool(), comment_reply_id).await?;
if local_user_view.person.id != read_comment_reply.recipient_id {
return Err(LemmyError::from_message("couldnt_update_comment"));
@ -38,18 +35,19 @@ impl Perform for MarkCommentReplyAsRead {
let comment_reply_id = read_comment_reply.id;
let read = Some(data.read);
blocking(context.pool(), move |conn| {
CommentReply::update(conn, comment_reply_id, &CommentReplyUpdateForm { read })
})
.await?
CommentReply::update(
context.pool(),
comment_reply_id,
&CommentReplyUpdateForm { read },
)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
let comment_reply_id = read_comment_reply.id;
let person_id = local_user_view.person.id;
let comment_reply_view = blocking(context.pool(), move |conn| {
CommentReplyView::read(conn, comment_reply_id, Some(person_id))
})
.await??;
let comment_reply_view =
CommentReplyView::read(context.pool(), comment_reply_id, Some(person_id)).await?;
Ok(CommentReplyResponse { comment_reply_view })
}

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{GetUnreadCount, GetUnreadCountResponse},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_views::structs::PrivateMessageView;
use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView};
@ -25,20 +25,12 @@ impl Perform for GetUnreadCount {
let person_id = local_user_view.person.id;
let replies = blocking(context.pool(), move |conn| {
CommentReplyView::get_unread_replies(conn, person_id)
})
.await??;
let replies = CommentReplyView::get_unread_replies(context.pool(), person_id).await?;
let mentions = blocking(context.pool(), move |conn| {
PersonMentionView::get_unread_mentions(conn, person_id)
})
.await??;
let mentions = PersonMentionView::get_unread_mentions(context.pool(), person_id).await?;
let private_messages = blocking(context.pool(), move |conn| {
PrivateMessageView::get_unread_messages(conn, person_id)
})
.await??;
let private_messages =
PrivateMessageView::get_unread_messages(context.pool(), person_id).await?;
let res = Self::Response {
replies,

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{GetReportCount, GetReportCountResponse},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_views::structs::{CommentReportView, PostReportView, PrivateMessageReportView};
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -26,23 +26,14 @@ impl Perform for GetReportCount {
let admin = local_user_view.person.admin;
let community_id = data.community_id;
let comment_reports = blocking(context.pool(), move |conn| {
CommentReportView::get_report_count(conn, person_id, admin, community_id)
})
.await??;
let comment_reports =
CommentReportView::get_report_count(context.pool(), person_id, admin, community_id).await?;
let post_reports = blocking(context.pool(), move |conn| {
PostReportView::get_report_count(conn, person_id, admin, community_id)
})
.await??;
let post_reports =
PostReportView::get_report_count(context.pool(), person_id, admin, community_id).await?;
let private_message_reports = if admin && community_id.is_none() {
Some(
blocking(context.pool(), move |conn| {
PrivateMessageReportView::get_report_count(conn)
})
.await??,
)
Some(PrivateMessageReportView::get_report_count(context.pool()).await?)
} else {
None
};

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{PasswordReset, PasswordResetResponse},
utils::{blocking, send_password_reset_email},
utils::send_password_reset_email,
};
use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -22,11 +22,9 @@ impl Perform for PasswordReset {
// Fetch that email
let email = data.email.to_lowercase();
let local_user_view = blocking(context.pool(), move |conn| {
LocalUserView::find_by_email(conn, &email)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;
let local_user_view = LocalUserView::find_by_email(context.pool(), &email)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;
// Email the pure token to the user.
send_password_reset_email(&local_user_view, context.pool(), context.settings()).await?;

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{LoginResponse, SaveUserSettings},
utils::{blocking, get_local_user_view_from_jwt, send_verification_email},
utils::{get_local_user_view_from_jwt, send_verification_email},
};
use lemmy_db_schema::{
source::{
@ -35,7 +35,7 @@ impl Perform for SaveUserSettings {
let data: &SaveUserSettings = self;
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_site = LocalSite::read(context.pool()).await?;
let avatar = diesel_option_overwrite_to_url(&data.avatar)?;
let banner = diesel_option_overwrite_to_url(&data.banner)?;
@ -97,17 +97,12 @@ impl Perform for SaveUserSettings {
.banner(banner)
.build();
blocking(context.pool(), move |conn| {
Person::update(conn, person_id, &person_form)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "user_already_exists"))?;
Person::update(context.pool(), person_id, &person_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "user_already_exists"))?;
if let Some(discussion_languages) = data.discussion_languages.clone() {
blocking(context.pool(), move |conn| {
LocalUserLanguage::update(conn, discussion_languages, local_user_id)
})
.await??;
LocalUserLanguage::update(context.pool(), discussion_languages, local_user_id).await?;
}
let local_user_form = LocalUserUpdateForm::builder()
@ -125,10 +120,7 @@ impl Perform for SaveUserSettings {
.interface_language(data.interface_language.to_owned())
.build();
let local_user_res = blocking(context.pool(), move |conn| {
LocalUser::update(conn, local_user_id, &local_user_form)
})
.await?;
let local_user_res = LocalUser::update(context.pool(), local_user_id, &local_user_form).await;
let updated_local_user = match local_user_res {
Ok(u) => u,
Err(e) => {

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
person::{VerifyEmail, VerifyEmailResponse},
utils::{blocking, send_email_verification_success},
utils::send_email_verification_success,
};
use lemmy_db_schema::{
source::{
@ -25,11 +25,9 @@ impl Perform for VerifyEmail {
_websocket_id: Option<usize>,
) -> Result<Self::Response, LemmyError> {
let token = self.token.clone();
let verification = blocking(context.pool(), move |conn| {
EmailVerification::read_for_token(conn, &token)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "token_not_found"))?;
let verification = EmailVerification::read_for_token(context.pool(), &token)
.await
.map_err(|e| LemmyError::from_error_message(e, "token_not_found"))?;
let form = LocalUserUpdateForm::builder()
// necessary in case this is a new signup
@ -38,22 +36,14 @@ impl Perform for VerifyEmail {
.email(Some(Some(verification.email)))
.build();
let local_user_id = verification.local_user_id;
blocking(context.pool(), move |conn| {
LocalUser::update(conn, local_user_id, &form)
})
.await??;
let local_user_view = blocking(context.pool(), move |conn| {
LocalUserView::read(conn, local_user_id)
})
.await??;
LocalUser::update(context.pool(), local_user_id, &form).await?;
let local_user_view = LocalUserView::read(context.pool(), local_user_id).await?;
send_email_verification_success(&local_user_view, context.settings())?;
blocking(context.pool(), move |conn| {
EmailVerification::delete_old_tokens_for_local_user(conn, local_user_id)
})
.await??;
EmailVerification::delete_old_tokens_for_local_user(context.pool(), local_user_id).await?;
Ok(VerifyEmailResponse {})
}

View file

@ -3,7 +3,6 @@ use actix_web::web::Data;
use lemmy_api_common::{
post::{CreatePostLike, PostResponse},
utils::{
blocking,
check_community_ban,
check_community_deleted_or_removed,
check_downvotes_enabled,
@ -42,16 +41,14 @@ impl Perform for CreatePostLike {
let data: &CreatePostLike = self;
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_site = LocalSite::read(context.pool()).await?;
// Don't do a downvote if site has downvotes disabled
check_downvotes_enabled(data.score, &local_site)?;
// Check for a community ban
let post_id = data.post_id;
let post: ApubPost = blocking(context.pool(), move |conn| Post::read(conn, post_id))
.await??
.into();
let post: ApubPost = Post::read(context.pool(), post_id).await?.into();
check_community_ban(local_user_view.person.id, post.community_id, context.pool()).await?;
check_community_deleted_or_removed(post.community_id, context.pool()).await?;
@ -64,10 +61,8 @@ impl Perform for CreatePostLike {
// Remove any likes first
let person_id = local_user_view.person.id;
blocking(context.pool(), move |conn| {
PostLike::remove(conn, person_id, post_id)
})
.await??;
PostLike::remove(context.pool(), person_id, post_id).await?;
let community_id = post.community_id;
let object = PostOrComment::Post(Box::new(post));
@ -76,9 +71,8 @@ impl Perform for CreatePostLike {
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
if do_add {
let like_form2 = like_form.clone();
let like = move |conn: &mut _| PostLike::like(conn, &like_form2);
blocking(context.pool(), like)
.await?
PostLike::like(context.pool(), &like_form2)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?;
Vote::send(

View file

@ -3,7 +3,6 @@ use actix_web::web::Data;
use lemmy_api_common::{
post::{LockPost, PostResponse},
utils::{
blocking,
check_community_ban,
check_community_deleted_or_removed,
get_local_user_view_from_jwt,
@ -39,7 +38,7 @@ impl Perform for LockPost {
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let post_id = data.post_id;
let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
let orig_post = Post::read(context.pool(), post_id).await?;
check_community_ban(
local_user_view.person.id,
@ -60,14 +59,12 @@ impl Perform for LockPost {
// Update the post
let post_id = data.post_id;
let locked = data.locked;
let updated_post: ApubPost = blocking(context.pool(), move |conn| {
Post::update(
conn,
post_id,
&PostUpdateForm::builder().locked(Some(locked)).build(),
)
})
.await??
let updated_post: ApubPost = Post::update(
context.pool(),
post_id,
&PostUpdateForm::builder().locked(Some(locked)).build(),
)
.await?
.into();
// Mod tables
@ -76,7 +73,7 @@ impl Perform for LockPost {
post_id: data.post_id,
locked: Some(locked),
};
blocking(context.pool(), move |conn| ModLockPost::create(conn, &form)).await??;
ModLockPost::create(context.pool(), &form).await?;
// apub updates
CreateOrUpdatePost::send(

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
post::{MarkPostAsRead, PostResponse},
utils::{blocking, get_local_user_view_from_jwt, mark_post_as_read, mark_post_as_unread},
utils::{get_local_user_view_from_jwt, mark_post_as_read, mark_post_as_unread},
};
use lemmy_db_views::structs::PostView;
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -33,10 +33,7 @@ impl Perform for MarkPostAsRead {
}
// Fetch it
let post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, post_id, Some(person_id))
})
.await??;
let post_view = PostView::read(context.pool(), post_id, Some(person_id)).await?;
let res = Self::Response { post_view };

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
post::{PostResponse, SavePost},
utils::{blocking, get_local_user_view_from_jwt, mark_post_as_read},
utils::{get_local_user_view_from_jwt, mark_post_as_read},
};
use lemmy_db_schema::{
source::post::{PostSaved, PostSavedForm},
@ -32,23 +32,18 @@ impl Perform for SavePost {
};
if data.save {
let save = move |conn: &mut _| PostSaved::save(conn, &post_saved_form);
blocking(context.pool(), save)
.await?
PostSaved::save(context.pool(), &post_saved_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_post"))?;
} else {
let unsave = move |conn: &mut _| PostSaved::unsave(conn, &post_saved_form);
blocking(context.pool(), unsave)
.await?
PostSaved::unsave(context.pool(), &post_saved_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_post"))?;
}
let post_id = data.post_id;
let person_id = local_user_view.person.id;
let post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, post_id, Some(person_id))
})
.await??;
let post_view = PostView::read(context.pool(), post_id, Some(person_id)).await?;
// Mark the post as read
mark_post_as_read(person_id, post_id, context.pool()).await?;

View file

@ -3,7 +3,6 @@ use actix_web::web::Data;
use lemmy_api_common::{
post::{PostResponse, StickyPost},
utils::{
blocking,
check_community_ban,
check_community_deleted_or_removed,
get_local_user_view_from_jwt,
@ -39,7 +38,7 @@ impl Perform for StickyPost {
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let post_id = data.post_id;
let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
let orig_post = Post::read(context.pool(), post_id).await?;
check_community_ban(
local_user_view.person.id,
@ -60,14 +59,12 @@ impl Perform for StickyPost {
// Update the post
let post_id = data.post_id;
let stickied = data.stickied;
let updated_post: ApubPost = blocking(context.pool(), move |conn| {
Post::update(
conn,
post_id,
&PostUpdateForm::builder().stickied(Some(stickied)).build(),
)
})
.await??
let updated_post: ApubPost = Post::update(
context.pool(),
post_id,
&PostUpdateForm::builder().stickied(Some(stickied)).build(),
)
.await?
.into();
// Mod tables
@ -76,10 +73,8 @@ impl Perform for StickyPost {
post_id: data.post_id,
stickied: Some(stickied),
};
blocking(context.pool(), move |conn| {
ModStickyPost::create(conn, &form)
})
.await??;
ModStickyPost::create(context.pool(), &form).await?;
// Apub updates
// TODO stickied should pry work like locked for ease of use

View file

@ -3,7 +3,7 @@ use activitypub_federation::core::object_id::ObjectId;
use actix_web::web::Data;
use lemmy_api_common::{
post::{CreatePostReport, PostReportResponse},
utils::{blocking, check_community_ban, get_local_user_view_from_jwt},
utils::{check_community_ban, get_local_user_view_from_jwt},
};
use lemmy_apub::protocol::activities::community::report::Report;
use lemmy_db_schema::{
@ -31,17 +31,14 @@ impl Perform for CreatePostReport {
let data: &CreatePostReport = self;
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_site = LocalSite::read(context.pool()).await?;
let reason = self.reason.trim();
check_report_reason(reason, &local_site)?;
let person_id = local_user_view.person.id;
let post_id = data.post_id;
let post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, post_id, None)
})
.await??;
let post_view = PostView::read(context.pool(), post_id, None).await?;
check_community_ban(person_id, post_view.community.id, context.pool()).await?;
@ -54,16 +51,11 @@ impl Perform for CreatePostReport {
reason: reason.to_owned(),
};
let report = blocking(context.pool(), move |conn| {
PostReport::report(conn, &report_form)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
let report = PostReport::report(context.pool(), &report_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
let post_report_view = blocking(context.pool(), move |conn| {
PostReportView::read(conn, report.id, person_id)
})
.await??;
let post_report_view = PostReportView::read(context.pool(), report.id, person_id).await?;
let res = PostReportResponse { post_report_view };

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
post::{ListPostReports, ListPostReportsResponse},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_views::post_report_view::PostReportQuery;
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -31,19 +31,17 @@ impl Perform for ListPostReports {
let page = data.page;
let limit = data.limit;
let post_reports = blocking(context.pool(), move |conn| {
PostReportQuery::builder()
.conn(conn)
.my_person_id(person_id)
.admin(admin)
.community_id(community_id)
.unresolved_only(unresolved_only)
.page(page)
.limit(limit)
.build()
.list()
})
.await??;
let post_reports = PostReportQuery::builder()
.pool(context.pool())
.my_person_id(person_id)
.admin(admin)
.community_id(community_id)
.unresolved_only(unresolved_only)
.page(page)
.limit(limit)
.build()
.list()
.await?;
let res = ListPostReportsResponse { post_reports };

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
post::{PostReportResponse, ResolvePostReport},
utils::{blocking, get_local_user_view_from_jwt, is_mod_or_admin},
utils::{get_local_user_view_from_jwt, is_mod_or_admin},
};
use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};
use lemmy_db_views::structs::PostReportView;
@ -26,31 +26,22 @@ impl Perform for ResolvePostReport {
let report_id = data.report_id;
let person_id = local_user_view.person.id;
let report = blocking(context.pool(), move |conn| {
PostReportView::read(conn, report_id, person_id)
})
.await??;
let report = PostReportView::read(context.pool(), report_id, person_id).await?;
let person_id = local_user_view.person.id;
is_mod_or_admin(context.pool(), person_id, report.community.id).await?;
let resolved = data.resolved;
let resolve_fun = move |conn: &mut _| {
if resolved {
PostReport::resolve(conn, report_id, person_id)
} else {
PostReport::unresolve(conn, report_id, person_id)
}
};
if data.resolved {
PostReport::resolve(context.pool(), report_id, person_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
} else {
PostReport::unresolve(context.pool(), report_id, person_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
}
blocking(context.pool(), resolve_fun)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
let post_report_view = blocking(context.pool(), move |conn| {
PostReportView::read(conn, report_id, person_id)
})
.await??;
let post_report_view = PostReportView::read(context.pool(), report_id, person_id).await?;
let res = PostReportResponse { post_report_view };

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
private_message::{MarkPrivateMessageAsRead, PrivateMessageResponse},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_schema::{
source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
@ -27,10 +27,7 @@ impl Perform for MarkPrivateMessageAsRead {
// Checking permissions
let private_message_id = data.private_message_id;
let orig_private_message = blocking(context.pool(), move |conn| {
PrivateMessage::read(conn, private_message_id)
})
.await??;
let orig_private_message = PrivateMessage::read(context.pool(), private_message_id).await?;
if local_user_view.person.id != orig_private_message.recipient_id {
return Err(LemmyError::from_message("couldnt_update_private_message"));
}
@ -38,14 +35,12 @@ impl Perform for MarkPrivateMessageAsRead {
// Doing the update
let private_message_id = data.private_message_id;
let read = data.read;
blocking(context.pool(), move |conn| {
PrivateMessage::update(
conn,
private_message_id,
&PrivateMessageUpdateForm::builder().read(Some(read)).build(),
)
})
.await?
PrivateMessage::update(
context.pool(),
private_message_id,
&PrivateMessageUpdateForm::builder().read(Some(read)).build(),
)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
// No need to send an apub update

View file

@ -2,7 +2,7 @@ use crate::{check_report_reason, Perform};
use actix_web::web::Data;
use lemmy_api_common::{
private_message::{CreatePrivateMessageReport, PrivateMessageReportResponse},
utils::{blocking, get_local_user_view_from_jwt},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_schema::{
newtypes::CommunityId,
@ -29,17 +29,14 @@ impl Perform for CreatePrivateMessageReport {
) -> Result<Self::Response, LemmyError> {
let local_user_view =
get_local_user_view_from_jwt(&self.auth, context.pool(), context.secret()).await?;
let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_site = LocalSite::read(context.pool()).await?;
let reason = self.reason.trim();
check_report_reason(reason, &local_site)?;
let person_id = local_user_view.person.id;
let private_message_id = self.private_message_id;
let private_message = blocking(context.pool(), move |conn| {
PrivateMessage::read(conn, private_message_id)
})
.await??;
let private_message = PrivateMessage::read(context.pool(), private_message_id).await?;
let report_form = PrivateMessageReportForm {
creator_id: person_id,
@ -48,16 +45,12 @@ impl Perform for CreatePrivateMessageReport {
reason: reason.to_owned(),
};
let report = blocking(context.pool(), move |conn| {
PrivateMessageReport::report(conn, &report_form)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
let report = PrivateMessageReport::report(context.pool(), &report_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
let private_message_report_view = blocking(context.pool(), move |conn| {
PrivateMessageReportView::read(conn, report.id)
})
.await??;
let private_message_report_view =
PrivateMessageReportView::read(context.pool(), report.id).await?;
let res = PrivateMessageReportResponse {
private_message_report_view,

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
private_message::{ListPrivateMessageReports, ListPrivateMessageReportsResponse},
utils::{blocking, get_local_user_view_from_jwt, is_admin},
utils::{get_local_user_view_from_jwt, is_admin},
};
use lemmy_db_views::private_message_report_view::PrivateMessageReportQuery;
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -26,16 +26,14 @@ impl Perform for ListPrivateMessageReports {
let unresolved_only = self.unresolved_only;
let page = self.page;
let limit = self.limit;
let private_message_reports = blocking(context.pool(), move |conn| {
PrivateMessageReportQuery::builder()
.conn(conn)
.unresolved_only(unresolved_only)
.page(page)
.limit(limit)
.build()
.list()
})
.await??;
let private_message_reports = PrivateMessageReportQuery::builder()
.pool(context.pool())
.unresolved_only(unresolved_only)
.page(page)
.limit(limit)
.build()
.list()
.await?;
let res = ListPrivateMessageReportsResponse {
private_message_reports,

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
utils::{blocking, get_local_user_view_from_jwt, is_admin},
utils::{get_local_user_view_from_jwt, is_admin},
};
use lemmy_db_schema::{
newtypes::CommunityId,
@ -28,25 +28,20 @@ impl Perform for ResolvePrivateMessageReport {
is_admin(&local_user_view)?;
let resolved = self.resolved;
let report_id = self.report_id;
let person_id = local_user_view.person.id;
let resolve_fn = move |conn: &mut _| {
if resolved {
PrivateMessageReport::resolve(conn, report_id, person_id)
} else {
PrivateMessageReport::unresolve(conn, report_id, person_id)
}
};
if self.resolved {
PrivateMessageReport::resolve(context.pool(), report_id, person_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
} else {
PrivateMessageReport::unresolve(context.pool(), report_id, person_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
}
blocking(context.pool(), resolve_fn)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
let private_message_report_view = blocking(context.pool(), move |conn| {
PrivateMessageReportView::read(conn, report_id)
})
.await??;
let private_message_report_view =
PrivateMessageReportView::read(context.pool(), report_id).await?;
let res = PrivateMessageReportResponse {
private_message_report_view,

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
site::{GetSiteResponse, LeaveAdmin},
utils::{blocking, get_local_user_view_from_jwt, is_admin},
utils::{get_local_user_view_from_jwt, is_admin},
};
use lemmy_db_schema::{
source::{
@ -35,20 +35,18 @@ impl Perform for LeaveAdmin {
is_admin(&local_user_view)?;
// Make sure there isn't just one admin (so if one leaves, there will still be one left)
let admins = blocking(context.pool(), PersonViewSafe::admins).await??;
let admins = PersonViewSafe::admins(context.pool()).await?;
if admins.len() == 1 {
return Err(LemmyError::from_message("cannot_leave_admin"));
}
let person_id = local_user_view.person.id;
blocking(context.pool(), move |conn| {
Person::update(
conn,
person_id,
&PersonUpdateForm::builder().admin(Some(false)).build(),
)
})
.await??;
Person::update(
context.pool(),
person_id,
&PersonUpdateForm::builder().admin(Some(false)).build(),
)
.await?;
// Mod tables
let form = ModAddForm {
@ -57,14 +55,14 @@ impl Perform for LeaveAdmin {
removed: Some(true),
};
blocking(context.pool(), move |conn| ModAdd::create(conn, &form)).await??;
ModAdd::create(context.pool(), &form).await?;
// Reread site and admins
let site_view = blocking(context.pool(), SiteView::read_local).await??;
let admins = blocking(context.pool(), PersonViewSafe::admins).await??;
let site_view = SiteView::read_local(context.pool()).await?;
let admins = PersonViewSafe::admins(context.pool()).await?;
let all_languages = blocking(context.pool(), Language::read_all).await??;
let discussion_languages = blocking(context.pool(), SiteLanguage::read_local).await??;
let all_languages = Language::read_all(context.pool()).await?;
let discussion_languages = SiteLanguage::read_local(context.pool()).await?;
Ok(GetSiteResponse {
site_view,

View file

@ -2,13 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
site::{GetModlog, GetModlogResponse},
utils::{
blocking,
check_private_instance,
get_local_user_view_from_jwt_opt,
is_admin,
is_mod_or_admin,
},
utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_admin, is_mod_or_admin},
};
use lemmy_db_schema::{
newtypes::{CommunityId, PersonId},
@ -52,7 +46,7 @@ impl Perform for GetModlog {
let local_user_view =
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
.await?;
let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_site = LocalSite::read(context.pool()).await?;
check_private_instance(&local_user_view, &local_site)?;
@ -88,81 +82,43 @@ impl Perform for GetModlog {
hide_modlog_names,
};
let removed_posts = match type_ {
All | ModRemovePost => {
blocking(context.pool(), move |conn| {
ModRemovePostView::list(conn, params)
})
.await??
}
All | ModRemovePost => ModRemovePostView::list(context.pool(), params).await?,
_ => Default::default(),
};
let locked_posts = match type_ {
All | ModLockPost => {
blocking(context.pool(), move |conn| {
ModLockPostView::list(conn, params)
})
.await??
}
All | ModLockPost => ModLockPostView::list(context.pool(), params).await?,
_ => Default::default(),
};
let stickied_posts = match type_ {
All | ModStickyPost => {
blocking(context.pool(), move |conn| {
ModStickyPostView::list(conn, params)
})
.await??
}
All | ModStickyPost => ModStickyPostView::list(context.pool(), params).await?,
_ => Default::default(),
};
let removed_comments = match type_ {
All | ModRemoveComment => {
blocking(context.pool(), move |conn| {
ModRemoveCommentView::list(conn, params)
})
.await??
}
All | ModRemoveComment => ModRemoveCommentView::list(context.pool(), params).await?,
_ => Default::default(),
};
let banned_from_community = match type_ {
All | ModBanFromCommunity => {
blocking(context.pool(), move |conn| {
ModBanFromCommunityView::list(conn, params)
})
.await??
}
All | ModBanFromCommunity => ModBanFromCommunityView::list(context.pool(), params).await?,
_ => Default::default(),
};
let added_to_community = match type_ {
All | ModAddCommunity => {
blocking(context.pool(), move |conn| {
ModAddCommunityView::list(conn, params)
})
.await??
}
All | ModAddCommunity => ModAddCommunityView::list(context.pool(), params).await?,
_ => Default::default(),
};
let transferred_to_community = match type_ {
All | ModTransferCommunity => {
blocking(context.pool(), move |conn| {
ModTransferCommunityView::list(conn, params)
})
.await??
}
All | ModTransferCommunity => ModTransferCommunityView::list(context.pool(), params).await?,
_ => Default::default(),
};
let hidden_communities = match type_ {
All | ModHideCommunity if other_person_id.is_none() => {
blocking(context.pool(), move |conn| {
ModHideCommunityView::list(conn, params)
})
.await??
ModHideCommunityView::list(context.pool(), params).await?
}
_ => Default::default(),
};
@ -177,49 +133,46 @@ impl Perform for GetModlog {
admin_purged_posts,
admin_purged_comments,
) = if data.community_id.is_none() {
blocking(context.pool(), move |conn| {
Ok((
match type_ {
All | ModBan => ModBanView::list(conn, params)?,
_ => Default::default(),
},
match type_ {
All | ModAdd => ModAddView::list(conn, params)?,
_ => Default::default(),
},
match type_ {
All | ModRemoveCommunity if other_person_id.is_none() => {
ModRemoveCommunityView::list(conn, params)?
}
_ => Default::default(),
},
match type_ {
All | AdminPurgePerson if other_person_id.is_none() => {
AdminPurgePersonView::list(conn, params)?
}
_ => Default::default(),
},
match type_ {
All | AdminPurgeCommunity if other_person_id.is_none() => {
AdminPurgeCommunityView::list(conn, params)?
}
_ => Default::default(),
},
match type_ {
All | AdminPurgePost if other_person_id.is_none() => {
AdminPurgePostView::list(conn, params)?
}
_ => Default::default(),
},
match type_ {
All | AdminPurgeComment if other_person_id.is_none() => {
AdminPurgeCommentView::list(conn, params)?
}
_ => Default::default(),
},
)) as Result<_, LemmyError>
})
.await??
(
match type_ {
All | ModBan => ModBanView::list(context.pool(), params).await?,
_ => Default::default(),
},
match type_ {
All | ModAdd => ModAddView::list(context.pool(), params).await?,
_ => Default::default(),
},
match type_ {
All | ModRemoveCommunity if other_person_id.is_none() => {
ModRemoveCommunityView::list(context.pool(), params).await?
}
_ => Default::default(),
},
match type_ {
All | AdminPurgePerson if other_person_id.is_none() => {
AdminPurgePersonView::list(context.pool(), params).await?
}
_ => Default::default(),
},
match type_ {
All | AdminPurgeCommunity if other_person_id.is_none() => {
AdminPurgeCommunityView::list(context.pool(), params).await?
}
_ => Default::default(),
},
match type_ {
All | AdminPurgePost if other_person_id.is_none() => {
AdminPurgePostView::list(context.pool(), params).await?
}
_ => Default::default(),
},
match type_ {
All | AdminPurgeComment if other_person_id.is_none() => {
AdminPurgeCommentView::list(context.pool(), params).await?
}
_ => Default::default(),
},
)
} else {
Default::default()
};

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
site::{PurgeComment, PurgeItemResponse},
utils::{blocking, get_local_user_view_from_jwt, is_admin},
utils::{get_local_user_view_from_jwt, is_admin},
};
use lemmy_db_schema::{
source::{
@ -34,16 +34,13 @@ impl Perform for PurgeComment {
let comment_id = data.comment_id;
// Read the comment to get the post_id
let comment = blocking(context.pool(), move |conn| Comment::read(conn, comment_id)).await??;
let comment = Comment::read(context.pool(), comment_id).await?;
let post_id = comment.post_id;
// TODO read comments for pictrs images and purge them
blocking(context.pool(), move |conn| {
Comment::delete(conn, comment_id)
})
.await??;
Comment::delete(context.pool(), comment_id).await?;
// Mod tables
let reason = data.reason.to_owned();
@ -53,10 +50,7 @@ impl Perform for PurgeComment {
post_id,
};
blocking(context.pool(), move |conn| {
AdminPurgeComment::create(conn, &form)
})
.await??;
AdminPurgeComment::create(context.pool(), &form).await?;
Ok(PurgeItemResponse { success: true })
}

View file

@ -3,7 +3,7 @@ use actix_web::web::Data;
use lemmy_api_common::{
request::purge_image_from_pictrs,
site::{PurgeCommunity, PurgeItemResponse},
utils::{blocking, get_local_user_view_from_jwt, is_admin, purge_image_posts_for_community},
utils::{get_local_user_view_from_jwt, is_admin, purge_image_posts_for_community},
};
use lemmy_db_schema::{
source::{
@ -35,10 +35,7 @@ impl Perform for PurgeCommunity {
let community_id = data.community_id;
// Read the community to get its images
let community = blocking(context.pool(), move |conn| {
Community::read(conn, community_id)
})
.await??;
let community = Community::read(context.pool(), community_id).await?;
if let Some(banner) = community.banner {
purge_image_from_pictrs(context.client(), context.settings(), &banner)
@ -60,10 +57,7 @@ impl Perform for PurgeCommunity {
)
.await?;
blocking(context.pool(), move |conn| {
Community::delete(conn, community_id)
})
.await??;
Community::delete(context.pool(), community_id).await?;
// Mod tables
let reason = data.reason.to_owned();
@ -72,10 +66,7 @@ impl Perform for PurgeCommunity {
reason,
};
blocking(context.pool(), move |conn| {
AdminPurgeCommunity::create(conn, &form)
})
.await??;
AdminPurgeCommunity::create(context.pool(), &form).await?;
Ok(PurgeItemResponse { success: true })
}

View file

@ -3,7 +3,7 @@ use actix_web::web::Data;
use lemmy_api_common::{
request::purge_image_from_pictrs,
site::{PurgeItemResponse, PurgePerson},
utils::{blocking, get_local_user_view_from_jwt, is_admin, purge_image_posts_for_person},
utils::{get_local_user_view_from_jwt, is_admin, purge_image_posts_for_person},
};
use lemmy_db_schema::{
source::{
@ -34,7 +34,7 @@ impl Perform for PurgePerson {
// Read the person to get their images
let person_id = data.person_id;
let person = blocking(context.pool(), move |conn| Person::read(conn, person_id)).await??;
let person = Person::read(context.pool(), person_id).await?;
if let Some(banner) = person.banner {
purge_image_from_pictrs(context.client(), context.settings(), &banner)
@ -56,7 +56,7 @@ impl Perform for PurgePerson {
)
.await?;
blocking(context.pool(), move |conn| Person::delete(conn, person_id)).await??;
Person::delete(context.pool(), person_id).await?;
// Mod tables
let reason = data.reason.to_owned();
@ -65,10 +65,7 @@ impl Perform for PurgePerson {
reason,
};
blocking(context.pool(), move |conn| {
AdminPurgePerson::create(conn, &form)
})
.await??;
AdminPurgePerson::create(context.pool(), &form).await?;
Ok(PurgeItemResponse { success: true })
}

View file

@ -3,7 +3,7 @@ use actix_web::web::Data;
use lemmy_api_common::{
request::purge_image_from_pictrs,
site::{PurgeItemResponse, PurgePost},
utils::{blocking, get_local_user_view_from_jwt, is_admin},
utils::{get_local_user_view_from_jwt, is_admin},
};
use lemmy_db_schema::{
source::{
@ -35,7 +35,7 @@ impl Perform for PurgePost {
let post_id = data.post_id;
// Read the post to get the community_id
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
let post = Post::read(context.pool(), post_id).await?;
// Purge image
if let Some(url) = post.url {
@ -52,7 +52,7 @@ impl Perform for PurgePost {
let community_id = post.community_id;
blocking(context.pool(), move |conn| Post::delete(conn, post_id)).await??;
Post::delete(context.pool(), post_id).await?;
// Mod tables
let reason = data.reason.to_owned();
@ -62,10 +62,7 @@ impl Perform for PurgePost {
community_id,
};
blocking(context.pool(), move |conn| {
AdminPurgePost::create(conn, &form)
})
.await??;
AdminPurgePost::create(context.pool(), &form).await?;
Ok(PurgeItemResponse { success: true })
}

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
site::{ApproveRegistrationApplication, RegistrationApplicationResponse},
utils::{blocking, get_local_user_view_from_jwt, is_admin, send_application_approved_email},
utils::{get_local_user_view_from_jwt, is_admin, send_application_approved_email},
};
use lemmy_db_schema::{
source::{
@ -41,10 +41,8 @@ impl Perform for ApproveRegistrationApplication {
deny_reason,
};
let registration_application = blocking(context.pool(), move |conn| {
RegistrationApplication::update(conn, app_id, &app_form)
})
.await??;
let registration_application =
RegistrationApplication::update(context.pool(), app_id, &app_form).await?;
// Update the local_user row
let local_user_form = LocalUserUpdateForm::builder()
@ -52,16 +50,10 @@ impl Perform for ApproveRegistrationApplication {
.build();
let approved_user_id = registration_application.local_user_id;
blocking(context.pool(), move |conn| {
LocalUser::update(conn, approved_user_id, &local_user_form)
})
.await??;
LocalUser::update(context.pool(), approved_user_id, &local_user_form).await?;
if data.approve {
let approved_local_user_view = blocking(context.pool(), move |conn| {
LocalUserView::read(conn, approved_user_id)
})
.await??;
let approved_local_user_view = LocalUserView::read(context.pool(), approved_user_id).await?;
if approved_local_user_view.local_user.email.is_some() {
send_application_approved_email(&approved_local_user_view, context.settings())?;
@ -69,10 +61,8 @@ impl Perform for ApproveRegistrationApplication {
}
// Read the view
let registration_application = blocking(context.pool(), move |conn| {
RegistrationApplicationView::read(conn, app_id)
})
.await??;
let registration_application =
RegistrationApplicationView::read(context.pool(), app_id).await?;
Ok(Self::Response {
registration_application,

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
site::{ListRegistrationApplications, ListRegistrationApplicationsResponse},
utils::{blocking, get_local_user_view_from_jwt, is_admin},
utils::{get_local_user_view_from_jwt, is_admin},
};
use lemmy_db_schema::source::local_site::LocalSite;
use lemmy_db_views::registration_application_view::RegistrationApplicationQuery;
@ -22,7 +22,7 @@ impl Perform for ListRegistrationApplications {
let data = self;
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_site = LocalSite::read(context.pool()).await?;
// Make sure user is an admin
is_admin(&local_user_view)?;
@ -32,17 +32,15 @@ impl Perform for ListRegistrationApplications {
let page = data.page;
let limit = data.limit;
let registration_applications = blocking(context.pool(), move |conn| {
RegistrationApplicationQuery::builder()
.conn(conn)
.unread_only(unread_only)
.verified_email_only(Some(verified_email_only))
.page(page)
.limit(limit)
.build()
.list()
})
.await??;
let registration_applications = RegistrationApplicationQuery::builder()
.pool(context.pool())
.unread_only(unread_only)
.verified_email_only(Some(verified_email_only))
.page(page)
.limit(limit)
.build()
.list()
.await?;
let res = Self::Response {
registration_applications,

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
site::{GetUnreadRegistrationApplicationCount, GetUnreadRegistrationApplicationCountResponse},
utils::{blocking, get_local_user_view_from_jwt, is_admin},
utils::{get_local_user_view_from_jwt, is_admin},
};
use lemmy_db_schema::source::local_site::LocalSite;
use lemmy_db_views::structs::RegistrationApplicationView;
@ -21,17 +21,15 @@ impl Perform for GetUnreadRegistrationApplicationCount {
let data = self;
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_site = LocalSite::read(context.pool()).await?;
// Only let admins do this
is_admin(&local_user_view)?;
let verified_email_only = local_site.require_email_verification;
let registration_applications = blocking(context.pool(), move |conn| {
RegistrationApplicationView::get_unread_count(conn, verified_email_only)
})
.await??;
let registration_applications =
RegistrationApplicationView::get_unread_count(context.pool(), verified_email_only).await?;
Ok(Self::Response {
registration_applications,

View file

@ -3,7 +3,7 @@ use actix_web::web::Data;
use diesel::NotFound;
use lemmy_api_common::{
site::{ResolveObject, ResolveObjectResponse},
utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt},
utils::{check_private_instance, get_local_user_view_from_jwt_opt},
};
use lemmy_apub::fetcher::search::{search_query_to_object_id, SearchableObjects};
use lemmy_db_schema::{newtypes::PersonId, source::local_site::LocalSite, utils::DbPool};
@ -25,7 +25,7 @@ impl Perform for ResolveObject {
let local_user_view =
get_local_user_view_from_jwt_opt(self.auth.as_ref(), context.pool(), context.secret())
.await?;
let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_site = LocalSite::read(context.pool()).await?;
check_private_instance(&local_user_view, &local_site)?;
let res = search_query_to_object_id(&self.q, local_user_view.is_none(), context)
@ -53,20 +53,19 @@ async fn convert_response(
match object {
Person(p) => {
removed_or_deleted = p.deleted;
res.person = Some(blocking(pool, move |conn| PersonViewSafe::read(conn, p.id)).await??)
res.person = Some(PersonViewSafe::read(pool, p.id).await?)
}
Community(c) => {
removed_or_deleted = c.deleted || c.removed;
res.community =
Some(blocking(pool, move |conn| CommunityView::read(conn, c.id, user_id)).await??)
res.community = Some(CommunityView::read(pool, c.id, user_id).await?)
}
Post(p) => {
removed_or_deleted = p.deleted || p.removed;
res.post = Some(blocking(pool, move |conn| PostView::read(conn, p.id, user_id)).await??)
res.post = Some(PostView::read(pool, p.id, user_id).await?)
}
Comment(c) => {
removed_or_deleted = c.deleted || c.removed;
res.comment = Some(blocking(pool, move |conn| CommentView::read(conn, c.id, user_id)).await??)
res.comment = Some(CommentView::read(pool, c.id, user_id).await?)
}
};
// if the object was deleted from database, dont return it

View file

@ -2,7 +2,7 @@ use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
site::{Search, SearchResponse},
utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt},
utils::{check_private_instance, get_local_user_view_from_jwt_opt},
};
use lemmy_apub::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity};
use lemmy_db_schema::{
@ -31,7 +31,7 @@ impl Perform for Search {
let local_user_view =
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
.await?;
let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_site = LocalSite::read(context.pool()).await?;
check_private_instance(&local_user_view, &local_site)?;
@ -63,68 +63,60 @@ impl Perform for Search {
let creator_id = data.creator_id;
match search_type {
SearchType::Posts => {
posts = blocking(context.pool(), move |conn| {
PostQuery::builder()
.conn(conn)
.sort(sort)
.listing_type(listing_type)
.community_id(community_id)
.community_actor_id(community_actor_id)
.creator_id(creator_id)
.local_user(local_user.as_ref())
.search_term(Some(q))
.page(page)
.limit(limit)
.build()
.list()
})
.await??;
posts = PostQuery::builder()
.pool(context.pool())
.sort(sort)
.listing_type(listing_type)
.community_id(community_id)
.community_actor_id(community_actor_id)
.creator_id(creator_id)
.local_user(local_user.as_ref())
.search_term(Some(q))
.page(page)
.limit(limit)
.build()
.list()
.await?;
}
SearchType::Comments => {
comments = blocking(context.pool(), move |conn| {
CommentQuery::builder()
.conn(conn)
.sort(sort.map(post_to_comment_sort_type))
.listing_type(listing_type)
.search_term(Some(q))
.community_id(community_id)
.community_actor_id(community_actor_id)
.creator_id(creator_id)
.local_user(local_user.as_ref())
.page(page)
.limit(limit)
.build()
.list()
})
.await??;
comments = CommentQuery::builder()
.pool(context.pool())
.sort(sort.map(post_to_comment_sort_type))
.listing_type(listing_type)
.search_term(Some(q))
.community_id(community_id)
.community_actor_id(community_actor_id)
.creator_id(creator_id)
.local_user(local_user.as_ref())
.page(page)
.limit(limit)
.build()
.list()
.await?;
}
SearchType::Communities => {
communities = blocking(context.pool(), move |conn| {
CommunityQuery::builder()
.conn(conn)
.sort(sort)
.listing_type(listing_type)
.search_term(Some(q))
.local_user(local_user.as_ref())
.page(page)
.limit(limit)
.build()
.list()
})
.await??;
communities = CommunityQuery::builder()
.pool(context.pool())
.sort(sort)
.listing_type(listing_type)
.search_term(Some(q))
.local_user(local_user.as_ref())
.page(page)
.limit(limit)
.build()
.list()
.await?;
}
SearchType::Users => {
users = blocking(context.pool(), move |conn| {
PersonQuery::builder()
.conn(conn)
.sort(sort)
.search_term(Some(q))
.page(page)
.limit(limit)
.build()
.list()
})
.await??;
users = PersonQuery::builder()
.pool(context.pool())
.sort(sort)
.search_term(Some(q))
.page(page)
.limit(limit)
.build()
.list()
.await?;
}
SearchType::All => {
// If the community or creator is included, dont search communities or users
@ -133,62 +125,56 @@ impl Perform for Search {
let community_actor_id_2 = community_actor_id.to_owned();
let local_user_ = local_user.clone();
posts = blocking(context.pool(), move |conn| {
PostQuery::builder()
.conn(conn)
.sort(sort)
.listing_type(listing_type)
.community_id(community_id)
.community_actor_id(community_actor_id_2)
.creator_id(creator_id)
.local_user(local_user_.as_ref())
.search_term(Some(q))
.page(page)
.limit(limit)
.build()
.list()
})
.await??;
posts = PostQuery::builder()
.pool(context.pool())
.sort(sort)
.listing_type(listing_type)
.community_id(community_id)
.community_actor_id(community_actor_id_2)
.creator_id(creator_id)
.local_user(local_user_.as_ref())
.search_term(Some(q))
.page(page)
.limit(limit)
.build()
.list()
.await?;
let q = data.q.to_owned();
let community_actor_id = community_actor_id.to_owned();
let local_user_ = local_user.clone();
comments = blocking(context.pool(), move |conn| {
CommentQuery::builder()
.conn(conn)
.sort(sort.map(post_to_comment_sort_type))
.listing_type(listing_type)
.search_term(Some(q))
.community_id(community_id)
.community_actor_id(community_actor_id)
.creator_id(creator_id)
.local_user(local_user_.as_ref())
.page(page)
.limit(limit)
.build()
.list()
})
.await??;
comments = CommentQuery::builder()
.pool(context.pool())
.sort(sort.map(post_to_comment_sort_type))
.listing_type(listing_type)
.search_term(Some(q))
.community_id(community_id)
.community_actor_id(community_actor_id)
.creator_id(creator_id)
.local_user(local_user_.as_ref())
.page(page)
.limit(limit)
.build()
.list()
.await?;
let q = data.q.to_owned();
communities = if community_or_creator_included {
vec![]
} else {
blocking(context.pool(), move |conn| {
CommunityQuery::builder()
.conn(conn)
.sort(sort)
.listing_type(listing_type)
.search_term(Some(q))
.local_user(local_user.as_ref())
.page(page)
.limit(limit)
.build()
.list()
})
.await??
CommunityQuery::builder()
.pool(context.pool())
.sort(sort)
.listing_type(listing_type)
.search_term(Some(q))
.local_user(local_user.as_ref())
.page(page)
.limit(limit)
.build()
.list()
.await?
};
let q = data.q.to_owned();
@ -196,35 +182,31 @@ impl Perform for Search {
users = if community_or_creator_included {
vec![]
} else {
blocking(context.pool(), move |conn| {
PersonQuery::builder()
.conn(conn)
.sort(sort)
.search_term(Some(q))
.page(page)
.limit(limit)
.build()
.list()
})
.await??
};
}
SearchType::Url => {
posts = blocking(context.pool(), move |conn| {
PostQuery::builder()
.conn(conn)
PersonQuery::builder()
.pool(context.pool())
.sort(sort)
.listing_type(listing_type)
.community_id(community_id)
.community_actor_id(community_actor_id)
.creator_id(creator_id)
.url_search(Some(q))
.search_term(Some(q))
.page(page)
.limit(limit)
.build()
.list()
})
.await??;
.await?
};
}
SearchType::Url => {
posts = PostQuery::builder()
.pool(context.pool())
.sort(sort)
.listing_type(listing_type)
.community_id(community_id)
.community_actor_id(community_actor_id)
.creator_id(creator_id)
.url_search(Some(q))
.page(page)
.limit(limit)
.build()
.list()
.await?;
}
};

View file

@ -24,11 +24,11 @@ lemmy_db_views_moderator = { version = "=0.16.5", path = "../db_views_moderator"
lemmy_db_views_actor = { version = "=0.16.5", path = "../db_views_actor" }
lemmy_db_schema = { version = "=0.16.5", path = "../db_schema", default-features = false }
lemmy_utils = { version = "=0.16.5", path = "../utils", optional = true }
serde = { version = "1.0.145", features = ["derive"] }
serde = { version = "1.0.147", features = ["derive"] }
url = "2.3.1"
actix-web = { version = "4.2.1", default-features = false, features = ["cookies"], optional = true }
chrono = { version = "0.4.22", features = ["serde"], optional = true }
diesel = { version = "2.0.0", optional = true }
diesel = { version = "2.0.2", optional = true }
tracing = { version = "0.1.36", optional = true }
rosetta-i18n = { version = "0.1.2", optional = true }
percent-encoding = { version = "2.2.0", optional = true }

View file

@ -125,10 +125,10 @@ pub struct CreateSite {
pub private_instance: Option<bool>,
pub default_theme: Option<String>,
pub default_post_listing_type: Option<String>,
pub application_email_admins: Option<bool>,
pub auth: Sensitive<String>,
pub hide_modlog_mod_names: Option<bool>,
pub legal_information: Option<String>,
pub application_email_admins: Option<bool>,
pub hide_modlog_mod_names: Option<bool>,
pub discussion_languages: Option<Vec<LanguageId>>,
pub slur_filter_regex: Option<String>,
pub actor_name_max_length: Option<i32>,
pub rate_limit_message: Option<i32>,
@ -152,6 +152,7 @@ pub struct CreateSite {
pub captcha_difficulty: Option<String>,
pub allowed_instances: Option<Vec<String>>,
pub blocked_instances: Option<Vec<String>>,
pub auth: Sensitive<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, Default)]

View file

@ -44,33 +44,13 @@ use rosetta_i18n::{Language, LanguageId};
use std::str::FromStr;
use tracing::warn;
pub async fn blocking<F, T>(pool: &DbPool, f: F) -> Result<T, LemmyError>
where
F: FnOnce(&mut diesel::PgConnection) -> T + Send + 'static,
T: Send + 'static,
{
let pool = pool.clone();
let blocking_span = tracing::info_span!("blocking operation");
actix_web::web::block(move || {
let entered = blocking_span.enter();
let mut conn = pool.get()?;
let res = (f)(&mut conn);
drop(entered);
Ok(res) as Result<T, LemmyError>
})
.await?
}
#[tracing::instrument(skip_all)]
pub async fn is_mod_or_admin(
pool: &DbPool,
person_id: PersonId,
community_id: CommunityId,
) -> Result<(), LemmyError> {
let is_mod_or_admin = blocking(pool, move |conn| {
CommunityView::is_mod_or_admin(conn, person_id, community_id)
})
.await?;
let is_mod_or_admin = CommunityView::is_mod_or_admin(pool, person_id, community_id).await?;
if !is_mod_or_admin {
return Err(LemmyError::from_message("not_a_mod_or_admin"));
}
@ -86,8 +66,8 @@ pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
#[tracing::instrument(skip_all)]
pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError> {
blocking(pool, move |conn| Post::read(conn, post_id))
.await?
Post::read(pool, post_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))
}
@ -99,11 +79,9 @@ pub async fn mark_post_as_read(
) -> Result<PostRead, LemmyError> {
let post_read_form = PostReadForm { post_id, person_id };
blocking(pool, move |conn| {
PostRead::mark_as_read(conn, &post_read_form)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read"))
PostRead::mark_as_read(pool, &post_read_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read"))
}
#[tracing::instrument(skip_all)]
@ -114,11 +92,9 @@ pub async fn mark_post_as_unread(
) -> Result<usize, LemmyError> {
let post_read_form = PostReadForm { post_id, person_id };
blocking(pool, move |conn| {
PostRead::mark_as_unread(conn, &post_read_form)
})
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read"))
PostRead::mark_as_unread(pool, &post_read_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read"))
}
#[tracing::instrument(skip_all)]
@ -131,8 +107,7 @@ pub async fn get_local_user_view_from_jwt(
.map_err(|e| e.with_message("not_logged_in"))?
.claims;
let local_user_id = LocalUserId(claims.sub);
let local_user_view =
blocking(pool, move |conn| LocalUserView::read(conn, local_user_id)).await??;
let local_user_view = LocalUserView::read(pool, local_user_id).await?;
check_user_valid(
local_user_view.person.banned,
local_user_view.person.ban_expires,
@ -181,10 +156,7 @@ pub async fn get_local_user_settings_view_from_jwt_opt(
.map_err(|e| e.with_message("not_logged_in"))?
.claims;
let local_user_id = LocalUserId(claims.sub);
let local_user_view = blocking(pool, move |conn| {
LocalUserSettingsView::read(conn, local_user_id)
})
.await??;
let local_user_view = LocalUserSettingsView::read(pool, local_user_id).await?;
check_user_valid(
local_user_view.person.banned,
local_user_view.person.ban_expires,
@ -222,9 +194,10 @@ pub async fn check_community_ban(
community_id: CommunityId,
pool: &DbPool,
) -> Result<(), LemmyError> {
let is_banned =
move |conn: &mut _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
if blocking(pool, is_banned).await? {
let is_banned = CommunityPersonBanView::get(pool, person_id, community_id)
.await
.is_ok();
if is_banned {
Err(LemmyError::from_message("community_ban"))
} else {
Ok(())
@ -236,8 +209,8 @@ pub async fn check_community_deleted_or_removed(
community_id: CommunityId,
pool: &DbPool,
) -> Result<(), LemmyError> {
let community = blocking(pool, move |conn| Community::read(conn, community_id))
.await?
let community = Community::read(pool, community_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
if community.deleted || community.removed {
Err(LemmyError::from_message("deleted"))
@ -260,8 +233,10 @@ pub async fn check_person_block(
potential_blocker_id: PersonId,
pool: &DbPool,
) -> Result<(), LemmyError> {
let is_blocked = move |conn: &mut _| PersonBlock::read(conn, potential_blocker_id, my_id).is_ok();
if blocking(pool, is_blocked).await? {
let is_blocked = PersonBlock::read(pool, potential_blocker_id, my_id)
.await
.is_ok();
if is_blocked {
Err(LemmyError::from_message("person_block"))
} else {
Ok(())
@ -294,9 +269,9 @@ pub async fn build_federated_instances(
) -> Result<Option<FederatedInstances>, LemmyError> {
if local_site.federation_enabled {
// TODO I hate that this requires 3 queries
let linked = blocking(pool, Instance::linked).await??;
let allowed = blocking(pool, Instance::allowlist).await??;
let blocked = blocking(pool, Instance::blocklist).await??;
let linked = Instance::linked(pool).await?;
let allowed = Instance::allowlist(pool).await?;
let blocked = Instance::blocklist(pool).await?;
// These can return empty vectors, so convert them to options
let allowed = (!allowed.is_empty()).then(|| allowed);
@ -374,10 +349,7 @@ pub async fn send_password_reset_email(
// Insert the row
let token2 = token.clone();
let local_user_id = user.local_user.id;
blocking(pool, move |conn| {
PasswordResetRequest::create_token(conn, local_user_id, &token2)
})
.await??;
PasswordResetRequest::create_token(pool, local_user_id, &token2).await?;
let email = &user.local_user.email.to_owned().expect("email");
let lang = get_interface_language(user);
@ -405,7 +377,7 @@ pub async fn send_verification_email(
settings.get_protocol_and_hostname(),
&form.verification_token
);
blocking(pool, move |conn| EmailVerification::create(conn, &form)).await??;
EmailVerification::create(pool, &form).await?;
let lang = get_interface_language(user);
let subject = lang.verify_email_subject(&settings.hostname);
@ -491,10 +463,7 @@ pub async fn send_new_applicant_email_to_admins(
settings: &Settings,
) -> Result<(), LemmyError> {
// Collect the admins with emails
let admins = blocking(pool, move |conn| {
LocalUserSettingsView::list_admins_with_emails(conn)
})
.await??;
let admins = LocalUserSettingsView::list_admins_with_emails(pool).await?;
let applications_link = &format!(
"{}/registration_applications",
@ -522,10 +491,7 @@ pub async fn check_registration_application(
{
// Fetch the registration, see if its denied
let local_user_id = local_user_view.local_user.id;
let registration = blocking(pool, move |conn| {
RegistrationApplication::find_by_local_user_id(conn, local_user_id)
})
.await??;
let registration = RegistrationApplication::find_by_local_user_id(pool, local_user_id).await?;
if let Some(deny_reason) = registration.deny_reason {
let lang = get_interface_language(local_user_view);
let registration_denied_message = format!("{}: {}", lang.registration_denied(), &deny_reason);
@ -554,10 +520,7 @@ pub async fn purge_image_posts_for_person(
settings: &Settings,
client: &ClientWithMiddleware,
) -> Result<(), LemmyError> {
let posts = blocking(pool, move |conn: &mut _| {
Post::fetch_pictrs_posts_for_creator(conn, banned_person_id)
})
.await??;
let posts = Post::fetch_pictrs_posts_for_creator(pool, banned_person_id).await?;
for post in posts {
if let Some(url) = post.url {
purge_image_from_pictrs(client, settings, &url).await.ok();
@ -569,10 +532,7 @@ pub async fn purge_image_posts_for_person(
}
}
blocking(pool, move |conn| {
Post::remove_pictrs_post_images_and_thumbnails_for_creator(conn, banned_person_id)
})
.await??;
Post::remove_pictrs_post_images_and_thumbnails_for_creator(pool, banned_person_id).await?;
Ok(())
}
@ -583,10 +543,7 @@ pub async fn purge_image_posts_for_community(
settings: &Settings,
client: &ClientWithMiddleware,
) -> Result<(), LemmyError> {
let posts = blocking(pool, move |conn: &mut _| {
Post::fetch_pictrs_posts_for_community(conn, banned_community_id)
})
.await??;
let posts = Post::fetch_pictrs_posts_for_community(pool, banned_community_id).await?;
for post in posts {
if let Some(url) = post.url {
purge_image_from_pictrs(client, settings, &url).await.ok();
@ -598,10 +555,7 @@ pub async fn purge_image_posts_for_community(
}
}
blocking(pool, move |conn| {
Post::remove_pictrs_post_images_and_thumbnails_for_community(conn, banned_community_id)
})
.await??;
Post::remove_pictrs_post_images_and_thumbnails_for_community(pool, banned_community_id).await?;
Ok(())
}
@ -613,7 +567,7 @@ pub async fn remove_user_data(
client: &ClientWithMiddleware,
) -> Result<(), LemmyError> {
// Purge user images
let person = blocking(pool, move |conn| Person::read(conn, banned_person_id)).await??;
let person = Person::read(pool, banned_person_id).await?;
if let Some(avatar) = person.avatar {
purge_image_from_pictrs(client, settings, &avatar)
.await
@ -626,23 +580,18 @@ pub async fn remove_user_data(
}
// Update the fields to None
blocking(pool, move |conn| {
Person::update(
conn,
banned_person_id,
&PersonUpdateForm::builder()
.avatar(Some(None))
.banner(Some(None))
.build(),
)
})
.await??;
Person::update(
pool,
banned_person_id,
&PersonUpdateForm::builder()
.avatar(Some(None))
.banner(Some(None))
.build(),
)
.await?;
// Posts
blocking(pool, move |conn: &mut _| {
Post::update_removed_for_creator(conn, banned_person_id, None, true)
})
.await??;
Post::update_removed_for_creator(pool, banned_person_id, None, true).await?;
// Purge image posts
purge_image_posts_for_person(banned_person_id, pool, settings, client).await?;
@ -650,10 +599,7 @@ pub async fn remove_user_data(
// Communities
// Remove all communities where they're the top mod
// for now, remove the communities manually
let first_mod_communities = blocking(pool, move |conn: &mut _| {
CommunityModeratorView::get_community_first_mods(conn)
})
.await??;
let first_mod_communities = CommunityModeratorView::get_community_first_mods(pool).await?;
// Filter to only this banned users top communities
let banned_user_first_communities: Vec<CommunityModeratorView> = first_mod_communities
@ -663,14 +609,12 @@ pub async fn remove_user_data(
for first_mod_community in banned_user_first_communities {
let community_id = first_mod_community.community.id;
blocking(pool, move |conn| {
Community::update(
conn,
community_id,
&CommunityUpdateForm::builder().removed(Some(true)).build(),
)
})
.await??;
Community::update(
pool,
community_id,
&CommunityUpdateForm::builder().removed(Some(true)).build(),
)
.await?;
// Delete the community images
if let Some(icon) = first_mod_community.community.icon {
@ -682,24 +626,19 @@ pub async fn remove_user_data(
.ok();
}
// Update the fields to None
blocking(pool, move |conn| {
Community::update(
conn,
community_id,
&CommunityUpdateForm::builder()
.icon(Some(None))
.banner(Some(None))
.build(),
)
})
.await??;
Community::update(
pool,
community_id,
&CommunityUpdateForm::builder()
.icon(Some(None))
.banner(Some(None))
.build(),
)
.await?;
}
// Comments
blocking(pool, move |conn: &mut _| {
Comment::update_removed_for_creator(conn, banned_person_id, true)
})
.await??;
Comment::update_removed_for_creator(pool, banned_person_id, true).await?;
Ok(())
}
@ -710,34 +649,27 @@ pub async fn remove_user_data_in_community(
pool: &DbPool,
) -> Result<(), LemmyError> {
// Posts
blocking(pool, move |conn| {
Post::update_removed_for_creator(conn, banned_person_id, Some(community_id), true)
})
.await??;
Post::update_removed_for_creator(pool, banned_person_id, Some(community_id), true).await?;
// Comments
// TODO Diesel doesn't allow updates with joins, so this has to be a loop
let comments = blocking(pool, move |conn| {
CommentQuery::builder()
.conn(conn)
.creator_id(Some(banned_person_id))
.community_id(Some(community_id))
.limit(Some(i64::MAX))
.build()
.list()
})
.await??;
let comments = CommentQuery::builder()
.pool(pool)
.creator_id(Some(banned_person_id))
.community_id(Some(community_id))
.limit(Some(i64::MAX))
.build()
.list()
.await?;
for comment_view in &comments {
let comment_id = comment_view.comment.id;
blocking(pool, move |conn| {
Comment::update(
conn,
comment_id,
&CommentUpdateForm::builder().removed(Some(true)).build(),
)
})
.await??;
Comment::update(
pool,
comment_id,
&CommentUpdateForm::builder().removed(Some(true)).build(),
)
.await?;
}
Ok(())
@ -750,7 +682,7 @@ pub async fn delete_user_account(
client: &ClientWithMiddleware,
) -> Result<(), LemmyError> {
// Delete their images
let person = blocking(pool, move |conn| Person::read(conn, person_id)).await??;
let person = Person::read(pool, person_id).await?;
if let Some(avatar) = person.avatar {
purge_image_from_pictrs(client, settings, &avatar)
.await
@ -764,21 +696,19 @@ pub async fn delete_user_account(
// No need to update avatar and banner, those are handled in Person::delete_account
// Comments
let permadelete = move |conn: &mut _| Comment::permadelete_for_creator(conn, person_id);
blocking(pool, permadelete)
.await?
Comment::permadelete_for_creator(pool, person_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
// Posts
let permadelete = move |conn: &mut _| Post::permadelete_for_creator(conn, person_id);
blocking(pool, permadelete)
.await?
Post::permadelete_for_creator(pool, person_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_post"))?;
// Purge image posts
purge_image_posts_for_person(person_id, pool, settings, client).await?;
blocking(pool, move |conn| Person::delete_account(conn, person_id)).await??;
Person::delete_account(pool, person_id).await?;
Ok(())
}