Revert "Fix some things"

This reverts commit 2bf8574bc8.
This commit is contained in:
dull b 2023-07-04 02:54:33 +00:00
parent 2bf8574bc8
commit 0a8d1f8caf
24 changed files with 94 additions and 94 deletions

View file

@ -39,7 +39,7 @@ pub struct VerifyUrlData(pub DbPool);
impl UrlVerifier for VerifyUrlData {
async fn verify(&self, url: &Url) -> Result<(), &'static str> {
let mut conn = get_conn(&self.0).await.expect("get connection");
let local_site_data = fetch_local_site_data(conn)
let local_site_data = fetch_local_site_data(&mut *conn)
.await
.expect("read local site data");
check_apub_id_valid(url, &local_site_data)?;
@ -99,12 +99,12 @@ pub(crate) struct LocalSiteData {
}
pub(crate) async fn fetch_local_site_data(
pool: &DbPool,
mut conn: impl DbConn,
) -> Result<LocalSiteData, diesel::result::Error> {
// LocalSite may be missing
let local_site = LocalSite::read(get_conn(pool).await?).await.ok();
let allowed_instances = Instance::allowlist(get_conn(pool).await?).await?;
let blocked_instances = Instance::blocklist(get_conn(pool).await?).await?;
let local_site = LocalSite::read(&mut *conn).await.ok();
let allowed_instances = Instance::allowlist(&mut *conn).await?;
let blocked_instances = Instance::blocklist(&mut *conn).await?;
Ok(LocalSiteData {
local_site,

View file

@ -9,7 +9,7 @@ use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{
source::{comment::Comment, person::Person, post::Post},
traits::Crud,
utils::{DbConn, DbPool},
utils::DbConn,
};
use lemmy_utils::{error::LemmyError, utils::mention::scrape_text_for_mentions};
use serde::{Deserialize, Serialize};
@ -92,16 +92,16 @@ pub async fn collect_non_local_mentions(
/// top-level comment, the creator of the post, otherwise the creator of the parent comment.
#[tracing::instrument(skip(conn, comment))]
async fn get_comment_parent_creator(
pool: &DbPool,
mut conn: impl DbConn,
comment: &Comment,
) -> Result<ApubPerson, LemmyError> {
let parent_creator_id = if let Some(parent_comment_id) = comment.parent_comment_id() {
let parent_comment = Comment::read(get_conn(pool).await?, parent_comment_id).await?;
let parent_comment = Comment::read(&mut *conn, parent_comment_id).await?;
parent_comment.creator_id
} else {
let parent_post_id = comment.post_id;
let parent_post = Post::read(get_conn(pool).await?, parent_post_id).await?;
let parent_post = Post::read(&mut *conn, parent_post_id).await?;
parent_post.creator_id
};
Ok(Person::read(get_conn(pool).await?, parent_creator_id).await?.into())
Ok(Person::read(&mut *conn, parent_creator_id).await?.into())
}

View file

@ -132,7 +132,7 @@ impl Object for ApubComment {
verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
verify_is_public(&note.to, &note.cc)?;
let community = note.community(context).await?;
let local_site_data = fetch_local_site_data(context.pool()).await?;
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
check_apub_id_valid_with_strictness(
note.id.inner(),

View file

@ -188,7 +188,7 @@ impl ApubCommunity {
) -> Result<Vec<Url>, LemmyError> {
let id = self.id;
let local_site_data = fetch_local_site_data(context.pool()).await?;
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
let follows = CommunityFollowerView::for_community(context.conn().await?, id).await?;
let inboxes: Vec<Url> = follows
.into_iter()

View file

@ -197,7 +197,7 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object<T: Into<Url> + C
pub(crate) async fn remote_instance_inboxes(mut conn: impl DbConn) -> Result<Vec<Url>, LemmyError> {
Ok(
Site::read_remote_sites(conn)
Site::read_remote_sites(&mut *conn)
.await?
.into_iter()
.map(|s| ApubSite::from(s).shared_inbox_or_inbox())

View file

@ -118,7 +118,7 @@ impl Object for ApubPerson {
expected_domain: &Url,
context: &Data<Self::DataType>,
) -> Result<(), LemmyError> {
let local_site_data = fetch_local_site_data(context.pool()).await?;
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
let slur_regex = &local_site_opt_to_slur_regex(&local_site_data.local_site);
check_slurs(&person.preferred_username, slur_regex)?;

View file

@ -143,7 +143,7 @@ impl Object for ApubPost {
verify_is_remote_object(page.id.inner(), context.settings())?;
};
let local_site_data = fetch_local_site_data(context.pool()).await?;
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
let community = page.community(context).await?;
check_apub_id_valid_with_strictness(

View file

@ -102,7 +102,7 @@ impl Object for ApubPrivateMessage {
verify_domains_match(note.id.inner(), expected_domain)?;
verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
let local_site_data = fetch_local_site_data(context.pool()).await?;
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
check_apub_id_valid_with_strictness(
note.id.inner(),

View file

@ -80,7 +80,7 @@ impl Group {
expected_domain: &Url,
context: &LemmyContext,
) -> Result<(), LemmyError> {
let local_site_data = fetch_local_site_data(context.pool()).await?;
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
check_apub_id_valid_with_strictness(
self.id.inner(),

View file

@ -35,7 +35,7 @@ impl LanguageTag {
lang: LanguageId,
mut conn: impl DbConn,
) -> Result<Option<LanguageTag>, LemmyError> {
let lang = Language::read_from_id(conn, lang).await?;
let lang = Language::read_from_id(&mut *conn, lang).await?;
// undetermined
if lang.id == UNDETERMINED_ID {
@ -55,7 +55,7 @@ impl LanguageTag {
let mut langs = Vec::<Language>::new();
for l in lang_ids {
langs.push(Language::read_from_id(conn, l).await?);
langs.push(Language::read_from_id(&mut *conn, l).await?);
}
let langs = langs
@ -73,7 +73,7 @@ impl LanguageTag {
mut conn: impl DbConn,
) -> Result<Option<LanguageId>, LemmyError> {
let identifier = lang.map(|l| l.identifier);
let language = Language::read_id_from_code(conn, identifier.as_deref()).await?;
let language = Language::read_id_from_code(&mut *conn, identifier.as_deref()).await?;
Ok(language)
}
@ -86,7 +86,7 @@ impl LanguageTag {
for l in langs {
let id = l.identifier;
language_ids.push(Language::read_id_from_code(conn, Some(&id)).await?);
language_ids.push(Language::read_id_from_code(&mut *conn, Some(&id)).await?);
}
Ok(language_ids.into_iter().flatten().collect())

View file

@ -11,7 +11,7 @@ impl CommentAggregates {
pub async fn read(mut conn: impl DbConn, comment_id: CommentId) -> Result<Self, Error> {
comment_aggregates::table
.filter(comment_aggregates::comment_id.eq(comment_id))
.first::<Self>(conn)
.first::<Self>(&mut *conn)
.await
}
@ -25,7 +25,7 @@ impl CommentAggregates {
comment_aggregates::score,
comment_aggregates::published,
)))
.get_result::<Self>(conn)
.get_result::<Self>(&mut *conn)
.await
}
}

View file

@ -11,7 +11,7 @@ impl CommunityAggregates {
pub async fn read(mut conn: impl DbConn, community_id: CommunityId) -> Result<Self, Error> {
community_aggregates::table
.filter(community_aggregates::community_id.eq(community_id))
.first::<Self>(conn)
.first::<Self>(&mut *conn)
.await
}
}

View file

@ -11,7 +11,7 @@ impl PersonAggregates {
pub async fn read(mut conn: impl DbConn, person_id: PersonId) -> Result<Self, Error> {
person_aggregates::table
.filter(person_aggregates::person_id.eq(person_id))
.first::<Self>(conn)
.first::<Self>(&mut *conn)
.await
}
}

View file

@ -18,7 +18,7 @@ impl PersonPostAggregates {
.on_conflict((person_id, post_id))
.do_update()
.set(form)
.get_result::<Self>(conn)
.get_result::<Self>(&mut *conn)
.await
}
pub async fn read(
@ -28,7 +28,7 @@ impl PersonPostAggregates {
) -> Result<Self, Error> {
person_post_aggregates
.filter(post_id.eq(post_id_).and(person_id.eq(person_id_)))
.first::<Self>(conn)
.first::<Self>(&mut *conn)
.await
}
}

View file

@ -11,7 +11,7 @@ impl PostAggregates {
pub async fn read(mut conn: impl DbConn, post_id: PostId) -> Result<Self, Error> {
post_aggregates::table
.filter(post_aggregates::post_id.eq(post_id))
.first::<Self>(conn)
.first::<Self>(&mut *conn)
.await
}
@ -25,7 +25,7 @@ impl PostAggregates {
post_aggregates::newest_comment_time_necro,
)),
))
.get_result::<Self>(conn)
.get_result::<Self>(&mut *conn)
.await
}
}

View file

@ -4,7 +4,7 @@ use diesel_async::RunQueryDsl;
impl SiteAggregates {
pub async fn read(mut conn: impl DbConn) -> Result<Self, Error> {
site_aggregates::table.first::<Self>(conn).await
site_aggregates::table.first::<Self>(&mut *conn).await
}
}

View file

@ -14,13 +14,13 @@ impl Crud for Activity {
type UpdateForm = ActivityUpdateForm;
type IdType = i32;
async fn read(mut conn: impl DbConn, activity_id: i32) -> Result<Self, Error> {
activity.find(activity_id).first::<Self>(conn).await
activity.find(activity_id).first::<Self>(&mut *conn).await
}
async fn create(mut conn: impl DbConn, new_activity: &Self::InsertForm) -> Result<Self, Error> {
insert_into(activity)
.values(new_activity)
.get_result::<Self>(conn)
.get_result::<Self>(&mut *conn)
.await
}
@ -31,12 +31,12 @@ impl Crud for Activity {
) -> Result<Self, Error> {
diesel::update(activity.find(activity_id))
.set(new_activity)
.get_result::<Self>(conn)
.get_result::<Self>(&mut *conn)
.await
}
async fn delete(mut conn: impl DbConn, activity_id: i32) -> Result<usize, Error> {
diesel::delete(activity.find(activity_id))
.execute(conn)
.execute(&mut *conn)
.await
}
}
@ -48,7 +48,7 @@ impl Activity {
) -> Result<Activity, Error> {
activity
.filter(ap_id.eq(object_id))
.first::<Self>(conn)
.first::<Self>(&mut *conn)
.await
}
}

View file

@ -62,14 +62,14 @@ impl LocalUserLanguage {
///
/// If no language_id vector is given, it will show all languages
pub async fn update(
pool: &DbPool,
mut conn: impl DbConn,
language_ids: Vec<LanguageId>,
for_local_user_id: LocalUserId,
) -> Result<(), Error> {
let mut lang_ids = convert_update_languages(get_conn(pool).await?, language_ids).await?;
let mut lang_ids = convert_update_languages(&mut *conn, language_ids).await?;
// No need to update if languages are unchanged
let current = LocalUserLanguage::read(get_conn(pool).await?, for_local_user_id).await?;
let current = LocalUserLanguage::read(&mut *conn, for_local_user_id).await?;
if current == lang_ids {
return Ok(());
}
@ -84,7 +84,7 @@ impl LocalUserLanguage {
lang_ids.push(UNDETERMINED_ID);
}
get_conn(pool).await?
conn
.build_transaction()
.run(|conn| {
Box::pin(async move {
@ -118,7 +118,7 @@ impl SiteLanguage {
.inner_join(site_language::table)
.order(site_language::id)
.select(site_language::language_id)
.load(conn)
.load(&mut *conn)
.await
}
@ -127,32 +127,32 @@ impl SiteLanguage {
.filter(site_language::site_id.eq(for_site_id))
.order(site_language::language_id)
.select(site_language::language_id)
.load(conn)
.load(&mut *conn)
.await
}
pub async fn read(pool: &DbPool, for_site_id: SiteId) -> Result<Vec<LanguageId>, Error> {
let langs = Self::read_raw(get_conn(pool).await?, for_site_id).await?;
pub async fn read(mut conn: impl DbConn, for_site_id: SiteId) -> Result<Vec<LanguageId>, Error> {
let langs = Self::read_raw(&mut *conn, for_site_id).await?;
convert_read_languages(get_conn(pool).await?, langs).await
convert_read_languages(&mut *conn, langs).await
}
pub async fn update(
pool: &DbPool,
mut conn: impl DbConn,
language_ids: Vec<LanguageId>,
site: &Site,
) -> Result<(), Error> {
let for_site_id = site.id;
let instance_id = site.instance_id;
let lang_ids = convert_update_languages(get_conn(pool).await?, language_ids).await?;
let lang_ids = convert_update_languages(&mut *conn, language_ids).await?;
// No need to update if languages are unchanged
let current = SiteLanguage::read(get_conn(pool).await?, site.id).await?;
let current = SiteLanguage::read(&mut *conn, site.id).await?;
if current == lang_ids {
return Ok(());
}
get_conn(pool).await?
conn
.build_transaction()
.run(|conn| {
Box::pin(async move {
@ -198,7 +198,7 @@ impl CommunityLanguage {
.filter(language_id.eq(for_language_id))
.filter(community_id.eq(for_community_id)),
))
.get_result(conn)
.get_result(&mut *conn)
.await?;
if is_allowed {
@ -216,7 +216,7 @@ impl CommunityLanguage {
/// community language, and it shouldnt be possible to post content in languages which are not
/// allowed by local site.
async fn limit_languages(
pool: &DbPool,
mut conn: impl DbConn,
for_instance_id: InstanceId,
) -> Result<(), Error> {
use crate::schema::{
@ -230,12 +230,12 @@ impl CommunityLanguage {
.filter(c::instance_id.eq(for_instance_id))
.filter(sl::language_id.is_null())
.select(cl::language_id)
.get_results(get_conn(pool).await?)
.get_results(&mut *conn)
.await?;
for c in community_languages {
delete(cl::community_language.filter(cl::language_id.eq(c)))
.execute(get_conn(pool).await?)
.execute(&mut *conn)
.await?;
}
Ok(())
@ -250,35 +250,35 @@ impl CommunityLanguage {
.filter(community_id.eq(for_community_id))
.order(language_id)
.select(language_id)
.get_results(conn)
.get_results(&mut *conn)
.await
}
pub async fn read(
pool: &DbPool
mut conn: impl DbConn,
for_community_id: CommunityId,
) -> Result<Vec<LanguageId>, Error> {
let langs = Self::read_raw(get_conn(pool).await?, for_community_id).await?;
convert_read_languages(get_conn(pool).await?, langs).await
let langs = Self::read_raw(&mut *conn, for_community_id).await?;
convert_read_languages(&mut *conn, langs).await
}
pub async fn update(
pool: &DbPool,
mut conn: impl DbConn,
mut language_ids: Vec<LanguageId>,
for_community_id: CommunityId,
) -> Result<(), Error> {
if language_ids.is_empty() {
language_ids = SiteLanguage::read_local_raw(get_conn(pool).await?).await?;
language_ids = SiteLanguage::read_local_raw(&mut *conn).await?;
}
let lang_ids = convert_update_languages(get_conn(pool).await?, language_ids).await?;
let lang_ids = convert_update_languages(&mut *conn, language_ids).await?;
// No need to update if languages are unchanged
let current = CommunityLanguage::read_raw(get_conn(pool).await?, for_community_id).await?;
let current = CommunityLanguage::read_raw(&mut *conn, for_community_id).await?;
if current == lang_ids {
return Ok(());
}
get_conn(pool).await?
conn
.build_transaction()
.run(|conn| {
Box::pin(async move {
@ -316,7 +316,7 @@ pub async fn default_post_language(
.filter(ul::local_user_id.eq(local_user_id))
.filter(cl::community_id.eq(community_id))
.select(cl::language_id)
.get_results::<LanguageId>(conn)
.get_results::<LanguageId>(&mut *conn)
.await?;
if intersection.len() == 1 {
@ -358,7 +358,7 @@ async fn convert_read_languages(
use crate::schema::language::dsl::{id, language};
let count: i64 = language
.select(count(id))
.first(conn)
.first(&mut *conn)
.await
.expect("read number of languages");
count as usize

View file

@ -18,12 +18,12 @@ impl CaptchaAnswer {
pub async fn insert(mut conn: impl DbConn, captcha: &CaptchaAnswerForm) -> Result<Self, Error> {
insert_into(captcha_answer)
.values(captcha)
.get_result::<Self>(conn)
.get_result::<Self>(&mut *conn)
.await
}
pub async fn check_captcha(
pool: &DbPool,
mut conn: impl DbConn,
to_check: CheckCaptchaAnswer,
) -> Result<bool, Error> {
// fetch requested captcha
@ -32,12 +32,12 @@ impl CaptchaAnswer {
.filter((uuid).eq(to_check.uuid))
.filter(lower(answer).eq(to_check.answer.to_lowercase().clone())),
))
.get_result::<bool>(get_conn(pool).await?)
.get_result::<bool>(&mut *conn)
.await?;
// delete checked captcha
delete(captcha_answer.filter(uuid.eq(to_check.uuid)))
.execute(get_conn(pool).await?)
.execute(&mut *conn)
.await?;
Ok(captcha_exists)

View file

@ -34,7 +34,7 @@ impl Comment {
deleted.eq(true),
updated.eq(naive_now()),
))
.get_results::<Self>(conn)
.get_results::<Self>(&mut *conn)
.await
}
@ -45,12 +45,12 @@ impl Comment {
) -> Result<Vec<Self>, Error> {
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
.set((removed.eq(new_removed), updated.eq(naive_now())))
.get_results::<Self>(conn)
.get_results::<Self>(&mut *conn)
.await
}
pub async fn create(
pool: &DbPool,
mut conn: impl DbConn,
comment_form: &CommentInsertForm,
parent_path: Option<&Ltree>,
) -> Result<Comment, Error> {
@ -60,7 +60,7 @@ impl Comment {
.on_conflict(ap_id)
.do_update()
.set(comment_form)
.get_result::<Self>(get_conn(pool).await?)
.get_result::<Self>(&mut *conn)
.await;
if let Ok(comment_insert) = inserted_comment {
@ -78,7 +78,7 @@ impl Comment {
let updated_comment = diesel::update(comment.find(comment_id))
.set(path.eq(ltree))
.get_result::<Self>(get_conn(pool).await?)
.get_result::<Self>(&mut *conn)
.await;
// Update the child count for the parent comment_aggregates
@ -111,7 +111,7 @@ where ca.comment_id = c.id"
);
sql_query(update_child_count_stmt)
.execute(get_conn(pool).await?)
.execute(&mut *conn)
.await?;
}
}
@ -128,7 +128,7 @@ where ca.comment_id = c.id"
Ok(
comment
.filter(ap_id.eq(object_id))
.first::<Comment>(conn)
.first::<Comment>(&mut *conn)
.await
.ok()
.map(Into::into),
@ -153,12 +153,12 @@ impl Crud for Comment {
type UpdateForm = CommentUpdateForm;
type IdType = CommentId;
async fn read(mut conn: impl DbConn, comment_id: CommentId) -> Result<Self, Error> {
comment.find(comment_id).first::<Self>(conn).await
comment.find(comment_id).first::<Self>(&mut *conn).await
}
async fn delete(mut conn: impl DbConn, comment_id: CommentId) -> Result<usize, Error> {
diesel::delete(comment.find(comment_id))
.execute(conn)
.execute(&mut *conn)
.await
}
@ -174,7 +174,7 @@ impl Crud for Comment {
) -> Result<Self, Error> {
diesel::update(comment.find(comment_id))
.set(comment_form)
.get_result::<Self>(conn)
.get_result::<Self>(&mut *conn)
.await
}
}
@ -190,7 +190,7 @@ impl Likeable for CommentLike {
.on_conflict((comment_id, person_id))
.do_update()
.set(comment_like_form)
.get_result::<Self>(conn)
.get_result::<Self>(&mut *conn)
.await
}
async fn remove(
@ -204,7 +204,7 @@ impl Likeable for CommentLike {
.filter(comment_id.eq(comment_id_))
.filter(person_id.eq(person_id_)),
)
.execute(conn)
.execute(&mut *conn)
.await
}
}
@ -222,7 +222,7 @@ impl Saveable for CommentSaved {
.on_conflict((comment_id, person_id))
.do_update()
.set(comment_saved_form)
.get_result::<Self>(conn)
.get_result::<Self>(&mut *conn)
.await
}
async fn unsave(
@ -235,7 +235,7 @@ impl Saveable for CommentSaved {
.filter(comment_id.eq(comment_saved_form.comment_id))
.filter(person_id.eq(comment_saved_form.person_id)),
)
.execute(conn)
.execute(&mut *conn)
.await
}
}

View file

@ -16,7 +16,7 @@ impl Crud for CommentReply {
async fn read(mut conn: impl DbConn, comment_reply_id: CommentReplyId) -> Result<Self, Error> {
comment_reply
.find(comment_reply_id)
.first::<Self>(conn)
.first::<Self>(&mut *conn)
.await
}
@ -31,7 +31,7 @@ impl Crud for CommentReply {
.on_conflict((recipient_id, comment_id))
.do_update()
.set(comment_reply_form)
.get_result::<Self>(conn)
.get_result::<Self>(&mut *conn)
.await
}
@ -42,7 +42,7 @@ impl Crud for CommentReply {
) -> Result<Self, Error> {
diesel::update(comment_reply.find(comment_reply_id))
.set(comment_reply_form)
.get_result::<Self>(conn)
.get_result::<Self>(&mut *conn)
.await
}
}
@ -58,7 +58,7 @@ impl CommentReply {
.filter(read.eq(false)),
)
.set(read.eq(true))
.get_results::<Self>(conn)
.get_results::<Self>(&mut *conn)
.await
}
@ -68,7 +68,7 @@ impl CommentReply {
) -> Result<Self, Error> {
comment_reply
.filter(comment_id.eq(for_comment_id))
.first::<Self>(conn)
.first::<Self>(&mut *conn)
.await
}
}

View file

@ -27,7 +27,7 @@ impl Reportable for CommentReport {
) -> Result<Self, Error> {
insert_into(comment_report)
.values(comment_report_form)
.get_result::<Self>(conn)
.get_result::<Self>(&mut *conn)
.await
}
@ -47,7 +47,7 @@ impl Reportable for CommentReport {
resolver_id.eq(by_resolver_id),
updated.eq(naive_now()),
))
.execute(conn)
.execute(&mut *conn)
.await
}
@ -67,7 +67,7 @@ impl Reportable for CommentReport {
resolver_id.eq(by_resolver_id),
updated.eq(naive_now()),
))
.execute(conn)
.execute(&mut *conn)
.await
}
}

View file

@ -30,19 +30,19 @@ impl Crud for Community {
async fn read(mut conn: impl DbConn, community_id: CommunityId) -> Result<Self, Error> {
community::table
.find(community_id)
.first::<Self>(conn)
.first::<Self>(&mut *conn)
.await
}
async fn delete(mut conn: impl DbConn, community_id: CommunityId) -> Result<usize, Error> {
diesel::delete(community::table.find(community_id))
.execute(conn)
.execute(&mut *conn)
.await
}
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error> {
let is_new_community = match &form.actor_id {
Some(id) => Community::read_from_apub_id(conn, id)
Some(id) => Community::read_from_apub_id(&mut *conn, id)
.await?
.is_none(),
None => true,

View file

@ -16,7 +16,7 @@ impl Blockable for CommunityBlock {
.on_conflict((person_id, community_id))
.do_update()
.set(community_block_form)
.get_result::<Self>(conn)
.get_result::<Self>(&mut *conn)
.await
}
async fn unblock(
@ -28,7 +28,7 @@ impl Blockable for CommunityBlock {
.filter(person_id.eq(community_block_form.person_id))
.filter(community_id.eq(community_block_form.community_id)),
)
.execute(conn)
.execute(&mut *conn)
.await
}
}