Fix write lock while read lock still present

This commit is contained in:
Neshura 2023-12-18 23:33:14 +01:00
parent b14d37e01c
commit f0e1bca08e
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -243,22 +243,23 @@ async fn handle_series(
let post_id = lemmy.post(post_data).await?; let post_id = lemmy.post(post_data).await?;
let read = data.read().await; {
if post_series_config.pin_settings.pin_new_post_community && !read.config.protected_communities.contains(&post_series_config.name) { let read = data.read().await;
let pinned_posts = lemmy.get_community_pinned(community_id).await?; if post_series_config.pin_settings.pin_new_post_community && !read.config.protected_communities.contains(&post_series_config.name) {
if !pinned_posts.is_empty() { let pinned_posts = lemmy.get_community_pinned(community_id).await?;
let community_pinned_post = &pinned_posts[0]; if !pinned_posts.is_empty() {
lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Community).await?; let community_pinned_post = &pinned_posts[0];
lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Community).await?;
}
lemmy.pin(post_id, PostFeatureType::Community).await?;
} else if read.config.protected_communities.contains(&post_series_config.name) {
let message = Message::Warning(format!("Community '{}' for Series '{}' is protected. Is this intended?", &post_series_config.name, series.slug));
if !read.messages.contains(&message) {
drop(read);
let mut write = data.write().await;
write.messages.push(message);
}
} }
lemmy.pin(post_id, PostFeatureType::Community).await?;
}
else if read.config.protected_communities.contains(&post_series_config.name) {
let message = Message::Warning(format!("Community '{}' for Series '{}' is protected. Is this intended?", &post_series_config.name, series.slug));
if !read.messages.contains(&message) {
drop(read);
let mut write = data.write().await;
write.messages.push(message);
};
} }
let read = data.read().await; let read = data.read().await;