Remove dead code #81

Merged
dessalines merged 7 commits from remove-dead-code into main 2020-08-12 12:30:54 +00:00
13 changed files with 45 additions and 134 deletions
Showing only changes of commit b597a13c83 - Show all commits

View File

@ -34,9 +34,8 @@ impl Crud<ActivityForm> for Activity {
activity.find(activity_id).first::<Self>(conn) activity.find(activity_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, activity_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _activity_id: i32) -> Result<usize, Error> {
use crate::schema::activity::dsl::*; unimplemented!()
diesel::delete(activity.find(activity_id)).execute(conn)
Review

Ugh, I get that these are never used... but it seems like a bad idea to change them to unimplemented and different from all the others. I'm open to it I guess tho.

Ugh, I get that these are never used... but it seems like a bad idea to change them to unimplemented and different from all the others. I'm open to it I guess tho.
Review

Or maybe we could add a Crud variant without the delete function?

Or maybe we could add a `Crud` variant without the delete function?
Review
[You can just make that one optional](https://stackoverflow.com/questions/51915551/how-does-one-define-optional-methods-on-traits).
Review

Oh and then you can remove all those unimplemented() ones.

Oh and then you can remove all those `unimplemented()` ones.
Review
Hrm its not showing the link well: https://stackoverflow.com/questions/51915551/how-does-one-define-optional-methods-on-traits
Review

Ah perfect!

Ah perfect!
} }
fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> { fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> {

View File

@ -23,8 +23,8 @@ impl Crud<CategoryForm> for Category {
category.find(category_id).first::<Self>(conn) category.find(category_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, category_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _category_id: i32) -> Result<usize, Error> {
diesel::delete(category.find(category_id)).execute(conn) unimplemented!()
} }
fn create(conn: &PgConnection, new_category: &CategoryForm) -> Result<Self, Error> { fn create(conn: &PgConnection, new_category: &CategoryForm) -> Result<Self, Error> {

View File

@ -55,9 +55,8 @@ impl Crud<CommentForm> for Comment {
comment.find(comment_id).first::<Self>(conn) comment.find(comment_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, comment_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _comment_id: i32) -> Result<usize, Error> {
use crate::schema::comment::dsl::*; unimplemented!()
diesel::delete(comment.find(comment_id)).execute(conn)
dessalines marked this conversation as resolved
Review

Comment, post, user and community deletes shouldn't be removed, bc we will use them once we implement purge. (I think one of the chapo team was maybe working on it)

Comment, post, user and community deletes shouldn't be removed, bc we will use them once we implement purge. (I think one of the chapo team was maybe working on it)
Review

Okay, restored them.

Okay, restored them.
} }
fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> { fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
@ -172,11 +171,8 @@ pub struct CommentLikeForm {
} }
impl Likeable<CommentLikeForm> for CommentLike { impl Likeable<CommentLikeForm> for CommentLike {
fn read(conn: &PgConnection, comment_id_from: i32) -> Result<Vec<Self>, Error> { fn read(_conn: &PgConnection, _comment_id_from: i32) -> Result<Vec<Self>, Error> {
use crate::schema::comment_like::dsl::*; unimplemented!()
comment_like
.filter(comment_id.eq(comment_id_from))
.load::<Self>(conn)
} }
fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> { fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {

View File

@ -60,9 +60,8 @@ impl Crud<CommunityForm> for Community {
community.find(community_id).first::<Self>(conn) community.find(community_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, community_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _community_id: i32) -> Result<usize, Error> {
use crate::schema::community::dsl::*; unimplemented!()
diesel::delete(community.find(community_id)).execute(conn)
} }
fn create(conn: &PgConnection, new_community: &CommunityForm) -> Result<Self, Error> { fn create(conn: &PgConnection, new_community: &CommunityForm) -> Result<Self, Error> {

View File

@ -41,9 +41,8 @@ impl Crud<ModRemovePostForm> for ModRemovePost {
mod_remove_post.find(from_id).first::<Self>(conn) mod_remove_post.find(from_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_remove_post::dsl::*; unimplemented!()
diesel::delete(mod_remove_post.find(from_id)).execute(conn)
} }
fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
@ -85,9 +84,8 @@ impl Crud<ModLockPostForm> for ModLockPost {
mod_lock_post.find(from_id).first::<Self>(conn) mod_lock_post.find(from_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_lock_post::dsl::*; unimplemented!()
diesel::delete(mod_lock_post.find(from_id)).execute(conn)
} }
fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
@ -129,9 +127,8 @@ impl Crud<ModStickyPostForm> for ModStickyPost {
mod_sticky_post.find(from_id).first::<Self>(conn) mod_sticky_post.find(from_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_sticky_post::dsl::*; unimplemented!()
diesel::delete(mod_sticky_post.find(from_id)).execute(conn)
} }
fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
@ -175,9 +172,8 @@ impl Crud<ModRemoveCommentForm> for ModRemoveComment {
mod_remove_comment.find(from_id).first::<Self>(conn) mod_remove_comment.find(from_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_remove_comment::dsl::*; unimplemented!()
diesel::delete(mod_remove_comment.find(from_id)).execute(conn)
} }
fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
@ -223,9 +219,8 @@ impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
mod_remove_community.find(from_id).first::<Self>(conn) mod_remove_community.find(from_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_remove_community::dsl::*; unimplemented!()
diesel::delete(mod_remove_community.find(from_id)).execute(conn)
} }
fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
@ -277,9 +272,8 @@ impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
mod_ban_from_community.find(from_id).first::<Self>(conn) mod_ban_from_community.find(from_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_ban_from_community::dsl::*; unimplemented!()
diesel::delete(mod_ban_from_community.find(from_id)).execute(conn)
} }
fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
@ -329,9 +323,8 @@ impl Crud<ModBanForm> for ModBan {
mod_ban.find(from_id).first::<Self>(conn) mod_ban.find(from_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_ban::dsl::*; unimplemented!()
diesel::delete(mod_ban.find(from_id)).execute(conn)
} }
fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
@ -373,9 +366,8 @@ impl Crud<ModAddCommunityForm> for ModAddCommunity {
mod_add_community.find(from_id).first::<Self>(conn) mod_add_community.find(from_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_add_community::dsl::*; unimplemented!()
diesel::delete(mod_add_community.find(from_id)).execute(conn)
} }
fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
@ -417,9 +409,8 @@ impl Crud<ModAddForm> for ModAdd {
mod_add.find(from_id).first::<Self>(conn) mod_add.find(from_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_add::dsl::*; unimplemented!()
diesel::delete(mod_add.find(from_id)).execute(conn)
} }
fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {

View File

@ -28,8 +28,8 @@ impl Crud<PasswordResetRequestForm> for PasswordResetRequest {
.find(password_reset_request_id) .find(password_reset_request_id)
.first::<Self>(conn) .first::<Self>(conn)
} }
fn delete(conn: &PgConnection, password_reset_request_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _password_reset_request_id: i32) -> Result<usize, Error> {
diesel::delete(password_reset_request.find(password_reset_request_id)).execute(conn) unimplemented!()
} }
fn create(conn: &PgConnection, form: &PasswordResetRequestForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &PasswordResetRequestForm) -> Result<Self, Error> {
insert_into(password_reset_request) insert_into(password_reset_request)

View File

@ -1,9 +1,8 @@
use crate::{ use crate::{
naive_now, naive_now,
schema::{post, post_like, post_read, post_saved}, schema::{post, post_like, post_saved},
Crud, Crud,
Likeable, Likeable,
Readable,
Saveable, Saveable,
}; };
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
@ -163,9 +162,8 @@ impl Crud<PostForm> for Post {
post.find(post_id).first::<Self>(conn) post.find(post_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, post_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _post_id: i32) -> Result<usize, Error> {
use crate::schema::post::dsl::*; unimplemented!()
diesel::delete(post.find(post_id)).execute(conn)
} }
fn create(conn: &PgConnection, new_post: &PostForm) -> Result<Self, Error> { fn create(conn: &PgConnection, new_post: &PostForm) -> Result<Self, Error> {
@ -201,11 +199,8 @@ pub struct PostLikeForm {
} }
impl Likeable<PostLikeForm> for PostLike { impl Likeable<PostLikeForm> for PostLike {
fn read(conn: &PgConnection, post_id_from: i32) -> Result<Vec<Self>, Error> { fn read(_conn: &PgConnection, _post_id_from: i32) -> Result<Vec<Self>, Error> {
use crate::schema::post_like::dsl::*; unimplemented!()
post_like
.filter(post_id.eq(post_id_from))
.load::<Self>(conn)
} }
fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> { fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> {
use crate::schema::post_like::dsl::*; use crate::schema::post_like::dsl::*;
@ -259,41 +254,6 @@ impl Saveable<PostSavedForm> for PostSaved {
} }
} }
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
#[belongs_to(Post)]
#[table_name = "post_read"]
pub struct PostRead {
pub id: i32,
pub post_id: i32,
pub user_id: i32,
pub published: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset, Clone)]
#[table_name = "post_read"]
pub struct PostReadForm {
pub post_id: i32,
pub user_id: i32,
}
impl Readable<PostReadForm> for PostRead {
fn mark_as_read(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<Self, Error> {
use crate::schema::post_read::dsl::*;
insert_into(post_read)
.values(post_read_form)
.get_result::<Self>(conn)
}
fn mark_as_unread(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<usize, Error> {
use crate::schema::post_read::dsl::*;
diesel::delete(
post_read
.filter(post_id.eq(post_read_form.post_id))
.filter(user_id.eq(post_read_form.user_id)),
)
.execute(conn)
}
}
nutomic marked this conversation as resolved
Review

This should all stay here, in case we add some functionality later on where your front page hides posts you've already read.

This should all stay here, in case we add some functionality later on where your front page hides posts you've already read.
Review

I dont really like this thing of implementing things that might be needed in the future, because either it never gets used, or it needs to get changed anyway at that time. And in the meantime its just making things more complicated for no benefit at all. Would you be happy if I add a comment with a link to this PR, so that the previous code is easy to find?

I dont really like this thing of implementing things that might be needed in the future, because either it never gets used, or it needs to get changed anyway at that time. And in the meantime its just making things more complicated for no benefit at all. Would you be happy if I add a comment with a link to this PR, so that the previous code is easy to find?
Review

Ugh, even removing the passing unit tests? No consider this something we will implement. I'll open up a ticket for hiding read posts.

Ugh, even removing the passing unit tests? No consider this something we will implement. I'll open up a ticket for hiding read posts.
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{
@ -436,26 +396,10 @@ mod tests {
published: inserted_post_saved.published, published: inserted_post_saved.published,
}; };
// Post Read
let post_read_form = PostReadForm {
post_id: inserted_post.id,
user_id: inserted_user.id,
};
let inserted_post_read = PostRead::mark_as_read(&conn, &post_read_form).unwrap();
let expected_post_read = PostRead {
id: inserted_post_read.id,
post_id: inserted_post.id,
user_id: inserted_user.id,
published: inserted_post_read.published,
};
let read_post = Post::read(&conn, inserted_post.id).unwrap(); let read_post = Post::read(&conn, inserted_post.id).unwrap();
let updated_post = Post::update(&conn, inserted_post.id, &new_post).unwrap(); let updated_post = Post::update(&conn, inserted_post.id, &new_post).unwrap();
let like_removed = PostLike::remove(&conn, &post_like_form).unwrap(); let like_removed = PostLike::remove(&conn, &post_like_form).unwrap();
let saved_removed = PostSaved::unsave(&conn, &post_saved_form).unwrap(); let saved_removed = PostSaved::unsave(&conn, &post_saved_form).unwrap();
let read_removed = PostRead::mark_as_unread(&conn, &post_read_form).unwrap();
let num_deleted = Post::delete(&conn, inserted_post.id).unwrap(); let num_deleted = Post::delete(&conn, inserted_post.id).unwrap();
Community::delete(&conn, inserted_community.id).unwrap(); Community::delete(&conn, inserted_community.id).unwrap();
User_::delete(&conn, inserted_user.id).unwrap(); User_::delete(&conn, inserted_user.id).unwrap();
@ -465,10 +409,8 @@ mod tests {
assert_eq!(expected_post, updated_post); assert_eq!(expected_post, updated_post);
assert_eq!(expected_post_like, inserted_post_like); assert_eq!(expected_post_like, inserted_post_like);
assert_eq!(expected_post_saved, inserted_post_saved); assert_eq!(expected_post_saved, inserted_post_saved);
assert_eq!(expected_post_read, inserted_post_read);
assert_eq!(1, like_removed); assert_eq!(1, like_removed);
assert_eq!(1, saved_removed); assert_eq!(1, saved_removed);
assert_eq!(1, read_removed);
assert_eq!(1, num_deleted); assert_eq!(1, num_deleted);
} }
} }

View File

@ -37,9 +37,8 @@ impl Crud<PrivateMessageForm> for PrivateMessage {
private_message.find(private_message_id).first::<Self>(conn) private_message.find(private_message_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, private_message_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _private_message_id: i32) -> Result<usize, Error> {
use crate::schema::private_message::dsl::*; unimplemented!()
diesel::delete(private_message.find(private_message_id)).execute(conn)
} }
fn create(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result<Self, Error> { fn create(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result<Self, Error> {

View File

@ -359,15 +359,6 @@ table! {
} }
} }
table! {
post_read (id) {
id -> Int4,
post_id -> Int4,
user_id -> Int4,
published -> Timestamp,
}
}
table! { table! {
post_saved (id) { post_saved (id) {
id -> Int4, id -> Int4,
@ -513,8 +504,6 @@ joinable!(post -> community (community_id));
joinable!(post -> user_ (creator_id)); joinable!(post -> user_ (creator_id));
joinable!(post_like -> post (post_id)); joinable!(post_like -> post (post_id));
joinable!(post_like -> user_ (user_id)); joinable!(post_like -> user_ (user_id));
joinable!(post_read -> post (post_id));
joinable!(post_read -> user_ (user_id));
joinable!(post_saved -> post (post_id)); joinable!(post_saved -> post (post_id));
joinable!(post_saved -> user_ (user_id)); joinable!(post_saved -> user_ (user_id));
joinable!(site -> user_ (creator_id)); joinable!(site -> user_ (creator_id));
@ -547,7 +536,6 @@ allow_tables_to_appear_in_same_query!(
post, post,
post_aggregates_fast, post_aggregates_fast,
post_like, post_like,
post_read,
post_saved, post_saved,
private_message, private_message,
site, site,

View File

@ -39,9 +39,8 @@ impl Crud<SiteForm> for Site {
site.first::<Self>(conn) site.first::<Self>(conn)
} }
fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _site_id: i32) -> Result<usize, Error> {
use crate::schema::site::dsl::*; unimplemented!()
diesel::delete(site.find(site_id)).execute(conn)
} }
fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> { fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {

View File

@ -70,8 +70,8 @@ impl Crud<UserForm> for User_ {
fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
user_.find(user_id).first::<Self>(conn) user_.find(user_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, user_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _user_id: i32) -> Result<usize, Error> {
diesel::delete(user_.find(user_id)).execute(conn) unimplemented!()
} }
fn create(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> {
insert_into(user_).values(form).get_result::<Self>(conn) insert_into(user_).values(form).get_result::<Self>(conn)

View File

@ -28,9 +28,8 @@ impl Crud<UserMentionForm> for UserMention {
user_mention.find(user_mention_id).first::<Self>(conn) user_mention.find(user_mention_id).first::<Self>(conn)
} }
fn delete(conn: &PgConnection, user_mention_id: i32) -> Result<usize, Error> { fn delete(_conn: &PgConnection, _user_mention_id: i32) -> Result<usize, Error> {
use crate::schema::user_mention::dsl::*; unimplemented!()
diesel::delete(user_mention.find(user_mention_id)).execute(conn)
} }
fn create(conn: &PgConnection, user_mention_form: &UserMentionForm) -> Result<Self, Error> { fn create(conn: &PgConnection, user_mention_form: &UserMentionForm) -> Result<Self, Error> {

View File

@ -159,9 +159,8 @@ impl<'a> UserQueryBuilder<'a> {
} }
impl UserView { impl UserView {
pub fn read(conn: &PgConnection, from_user_id: i32) -> Result<Self, Error> { pub fn read(_conn: &PgConnection, _from_user_id: i32) -> Result<Self, Error> {
use super::user_view::user_fast::dsl::*; unimplemented!()
user_fast.find(from_user_id).first::<Self>(conn)
} }
pub fn admins(conn: &PgConnection) -> Result<Vec<Self>, Error> { pub fn admins(conn: &PgConnection) -> Result<Vec<Self>, Error> {