mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-05-23 12:18:05 +00:00
Compare commits
4 commits
a3e2858791
...
ae01d2ecdc
Author | SHA1 | Date | |
---|---|---|---|
ae01d2ecdc | |||
9807b02efd | |||
95ed87e87e | |||
d3737d4453 |
|
@ -38,7 +38,7 @@ use url::Url;
|
|||
|
||||
impl CreateOrUpdatePage {
|
||||
pub(crate) async fn new(
|
||||
post: &ApubPost,
|
||||
post: ApubPost,
|
||||
actor: &ApubPerson,
|
||||
community: &ApubCommunity,
|
||||
kind: CreateOrUpdateType,
|
||||
|
@ -51,7 +51,7 @@ impl CreateOrUpdatePage {
|
|||
Ok(CreateOrUpdatePage {
|
||||
actor: actor.id().into(),
|
||||
to: vec![public()],
|
||||
object: post.clone().into_json(context).await?,
|
||||
object: post.into_json(context).await?,
|
||||
cc: vec![community.id()],
|
||||
kind,
|
||||
id: id.clone(),
|
||||
|
@ -77,7 +77,7 @@ impl CreateOrUpdatePage {
|
|||
.into();
|
||||
|
||||
let create_or_update =
|
||||
CreateOrUpdatePage::new(&post.into(), &person, &community, kind, &context).await?;
|
||||
CreateOrUpdatePage::new(post.into(), &person, &community, kind, &context).await?;
|
||||
let is_mod_action = create_or_update.object.is_mod_action(&context).await?;
|
||||
let activity = AnnouncableActivities::CreateOrUpdatePost(create_or_update);
|
||||
send_activity_in_community(
|
||||
|
|
|
@ -55,7 +55,7 @@ impl Collection for ApubCommunityOutbox {
|
|||
let mut ordered_items = vec![];
|
||||
for post_view in post_views {
|
||||
let create = CreateOrUpdatePage::new(
|
||||
&post_view.post.into(),
|
||||
post_view.post.into(),
|
||||
&post_view.creator.into(),
|
||||
owner,
|
||||
CreateOrUpdateType::Create,
|
||||
|
|
|
@ -43,20 +43,13 @@ impl LocalUserLanguage {
|
|||
};
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
|
||||
conn
|
||||
.build_transaction()
|
||||
.run(|conn| {
|
||||
Box::pin(async move {
|
||||
let langs = local_user_language
|
||||
.filter(local_user_id.eq(for_local_user_id))
|
||||
.order(language_id)
|
||||
.select(language_id)
|
||||
.get_results(conn)
|
||||
.await?;
|
||||
convert_read_languages(conn, langs).await
|
||||
}) as _
|
||||
})
|
||||
.await
|
||||
let langs = local_user_language
|
||||
.filter(local_user_id.eq(for_local_user_id))
|
||||
.order(language_id)
|
||||
.select(language_id)
|
||||
.get_results(conn)
|
||||
.await?;
|
||||
convert_read_languages(conn, langs).await
|
||||
}
|
||||
|
||||
/// Update the user's languages.
|
||||
|
@ -90,24 +83,33 @@ impl LocalUserLanguage {
|
|||
.build_transaction()
|
||||
.run(|conn| {
|
||||
Box::pin(async move {
|
||||
use crate::schema::local_user_language::dsl::{local_user_id, local_user_language};
|
||||
// Clear the current user languages
|
||||
delete(local_user_language.filter(local_user_id.eq(for_local_user_id)))
|
||||
.execute(conn)
|
||||
.await?;
|
||||
use crate::schema::local_user_language::dsl::{
|
||||
language_id,
|
||||
local_user_id,
|
||||
local_user_language,
|
||||
};
|
||||
// Delete old languages, not including new languages
|
||||
let delete_old = delete(local_user_language)
|
||||
.filter(local_user_id.eq(for_local_user_id))
|
||||
.filter(language_id.ne_all(&lang_ids))
|
||||
.execute(conn);
|
||||
|
||||
let forms = lang_ids
|
||||
.into_iter()
|
||||
.map(|l| LocalUserLanguageForm {
|
||||
.iter()
|
||||
.map(|&l| LocalUserLanguageForm {
|
||||
local_user_id: for_local_user_id,
|
||||
language_id: l,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
insert_into(local_user_language)
|
||||
// Insert new languages
|
||||
let insert_new = insert_into(local_user_language)
|
||||
.values(forms)
|
||||
.execute(conn)
|
||||
.await?;
|
||||
.on_conflict((language_id, local_user_id))
|
||||
.do_nothing()
|
||||
.execute(conn);
|
||||
|
||||
tokio::try_join!(delete_old, insert_new)?;
|
||||
Ok(())
|
||||
}) as _
|
||||
})
|
||||
|
@ -159,25 +161,30 @@ impl SiteLanguage {
|
|||
.build_transaction()
|
||||
.run(|conn| {
|
||||
Box::pin(async move {
|
||||
use crate::schema::site_language::dsl::{site_id, site_language};
|
||||
use crate::schema::site_language::dsl::{language_id, site_id, site_language};
|
||||
|
||||
// Clear the current languages
|
||||
delete(site_language.filter(site_id.eq(for_site_id)))
|
||||
.execute(conn)
|
||||
.await?;
|
||||
// Delete old languages, not including new languages
|
||||
let delete_old = delete(site_language)
|
||||
.filter(site_id.eq(for_site_id))
|
||||
.filter(language_id.ne_all(&lang_ids))
|
||||
.execute(conn);
|
||||
|
||||
let forms = lang_ids
|
||||
.into_iter()
|
||||
.map(|l| SiteLanguageForm {
|
||||
.iter()
|
||||
.map(|&l| SiteLanguageForm {
|
||||
site_id: for_site_id,
|
||||
language_id: l,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
insert_into(site_language)
|
||||
// Insert new languages
|
||||
let insert_new = insert_into(site_language)
|
||||
.values(forms)
|
||||
.get_result::<Self>(conn)
|
||||
.await?;
|
||||
.on_conflict((site_id, language_id))
|
||||
.do_nothing()
|
||||
.execute(conn);
|
||||
|
||||
tokio::try_join!(delete_old, insert_new)?;
|
||||
|
||||
CommunityLanguage::limit_languages(conn, instance_id).await?;
|
||||
|
||||
|
@ -278,8 +285,8 @@ impl CommunityLanguage {
|
|||
}
|
||||
|
||||
let form = lang_ids
|
||||
.into_iter()
|
||||
.map(|language_id| CommunityLanguageForm {
|
||||
.iter()
|
||||
.map(|&language_id| CommunityLanguageForm {
|
||||
community_id: for_community_id,
|
||||
language_id,
|
||||
})
|
||||
|
@ -289,25 +296,25 @@ impl CommunityLanguage {
|
|||
.build_transaction()
|
||||
.run(|conn| {
|
||||
Box::pin(async move {
|
||||
use crate::schema::community_language::dsl::{community_id, community_language};
|
||||
use diesel::result::DatabaseErrorKind::UniqueViolation;
|
||||
// Clear the current languages
|
||||
delete(community_language.filter(community_id.eq(for_community_id)))
|
||||
.execute(conn)
|
||||
.await?;
|
||||
use crate::schema::community_language::dsl::{
|
||||
community_id,
|
||||
community_language,
|
||||
language_id,
|
||||
};
|
||||
// Delete old languages, not including new languages
|
||||
let delete_old = delete(community_language)
|
||||
.filter(community_id.eq(for_community_id))
|
||||
.filter(language_id.ne_all(&lang_ids))
|
||||
.execute(conn);
|
||||
|
||||
let insert_res = insert_into(community_language)
|
||||
// Insert new languages
|
||||
let insert_new = insert_into(community_language)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await;
|
||||
.on_conflict((community_id, language_id))
|
||||
.do_nothing()
|
||||
.execute(conn);
|
||||
|
||||
if let Err(Error::DatabaseError(UniqueViolation, _info)) = insert_res {
|
||||
// race condition: this function was probably called simultaneously from another caller. ignore error
|
||||
// tracing::warn!("unique error: {_info:#?}");
|
||||
// _info.constraint_name() should be = "community_language_community_id_language_id_key"
|
||||
return Ok(());
|
||||
}
|
||||
insert_res?;
|
||||
tokio::try_join!(delete_old, insert_new)?;
|
||||
|
||||
Ok(())
|
||||
}) as _
|
||||
|
|
Loading…
Reference in a new issue