From d5efebbf4759412c4061abefbd619c404ab10b6d Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 21 Dec 2020 17:30:34 +0100 Subject: [PATCH 1/3] Split lemmy_db into lemmy_db_queries, lemmy_db_aggregates and lemmy_db_views --- Cargo.lock | 39 +++++++++++++++--- Cargo.toml | 6 ++- lemmy_api/Cargo.toml | 3 +- lemmy_api/src/comment.rs | 8 ++-- lemmy_api/src/community.rs | 18 ++++---- lemmy_api/src/lib.rs | 7 +++- lemmy_api/src/post.rs | 22 ++++------ lemmy_api/src/site.rs | 36 ++++++++-------- lemmy_api/src/user.rs | 26 ++++++------ lemmy_apub/Cargo.toml | 3 +- lemmy_apub/src/activities/receive/comment.rs | 3 +- .../src/activities/receive/comment_undo.rs | 3 +- .../src/activities/receive/community.rs | 7 +--- lemmy_apub/src/activities/receive/post.rs | 3 +- .../src/activities/receive/post_undo.rs | 3 +- .../src/activities/receive/private_message.rs | 6 +-- lemmy_apub/src/activities/send/community.rs | 3 +- lemmy_apub/src/fetcher.rs | 20 ++++----- lemmy_apub/src/http/community.rs | 6 +-- lemmy_apub/src/inbox/community_inbox.rs | 9 +--- lemmy_apub/src/objects/community.rs | 3 +- lemmy_db_aggregates/Cargo.toml | 11 +++++ .../src}/comment_aggregates.rs | 20 ++++----- .../src}/community_aggregates.rs | 10 +---- .../mod.rs => lemmy_db_aggregates/src/lib.rs | 0 .../src}/post_aggregates.rs | 10 +---- .../src}/site_aggregates.rs | 10 ++--- .../src}/user_aggregates.rs | 10 +---- {lemmy_db => lemmy_db_queries}/Cargo.toml | 2 +- {lemmy_db => lemmy_db_queries}/src/lib.rs | 41 +++++++++---------- .../src/source/activity.rs | 8 +++- .../src/source/category.rs | 2 +- .../src/source/comment.rs | 9 +--- .../src/source/comment_report.rs | 0 .../src/source/community.rs | 30 +------------- .../src/source/mod.rs | 0 .../src/source/moderator.rs | 2 +- .../src/source/password_reset_request.rs | 8 +++- .../src/source/post.rs | 2 +- .../src/source/post_report.rs | 0 .../src/source/private_message.rs | 8 +++- .../src/source/site.rs | 0 .../src/source/user.rs | 2 +- .../src/source/user_mention.rs | 2 +- lemmy_db_schema/src/lib.rs | 2 +- lemmy_db_schema/src/source/comment_report.rs | 4 +- lemmy_db_schema/src/source/post_report.rs | 4 +- lemmy_db_views/Cargo.toml | 11 +++++ .../src}/comment_report_view.rs | 3 +- .../src}/comment_view.rs | 12 +++--- .../src}/community/community_follower_view.rs | 3 +- .../community/community_moderator_view.rs | 3 +- .../src}/community/community_user_ban_view.rs | 2 +- .../src}/community/community_view.rs | 28 +++++++++++-- .../src}/community/mod.rs | 0 .../views/mod.rs => lemmy_db_views/src/lib.rs | 0 .../src}/moderator/mod.rs | 0 .../src}/moderator/mod_add_community_view.rs | 3 +- .../src}/moderator/mod_add_view.rs | 3 +- .../moderator/mod_ban_from_community_view.rs | 3 +- .../src}/moderator/mod_ban_view.rs | 3 +- .../src}/moderator/mod_lock_post_view.rs | 3 +- .../src}/moderator/mod_remove_comment_view.rs | 3 +- .../moderator/mod_remove_community_view.rs | 3 +- .../src}/moderator/mod_remove_post_view.rs | 3 +- .../src}/moderator/mod_sticky_post_view.rs | 3 +- .../src}/post_report_view.rs | 3 +- .../views => lemmy_db_views/src}/post_view.rs | 19 ++++----- .../src}/private_message_view.rs | 3 +- .../views => lemmy_db_views/src}/site_view.rs | 3 +- .../src}/user_mention_view.rs | 12 ++---- .../views => lemmy_db_views/src}/user_view.rs | 12 ++---- lemmy_structs/Cargo.toml | 3 +- lemmy_structs/src/comment.rs | 2 +- lemmy_structs/src/community.rs | 2 +- lemmy_structs/src/post.rs | 2 +- lemmy_structs/src/site.rs | 4 +- lemmy_structs/src/user.rs | 2 +- lemmy_utils/src/settings.rs | 2 +- lemmy_websocket/Cargo.toml | 2 +- src/routes/feeds.rs | 12 +++--- src/routes/nodeinfo.rs | 2 +- 82 files changed, 307 insertions(+), 298 deletions(-) create mode 100644 lemmy_db_aggregates/Cargo.toml rename {lemmy_db/src/aggregates => lemmy_db_aggregates/src}/comment_aggregates.rs (94%) rename {lemmy_db/src/aggregates => lemmy_db_aggregates/src}/community_aggregates.rs (97%) rename lemmy_db/src/aggregates/mod.rs => lemmy_db_aggregates/src/lib.rs (100%) rename {lemmy_db/src/aggregates => lemmy_db_aggregates/src}/post_aggregates.rs (97%) rename {lemmy_db/src/aggregates => lemmy_db_aggregates/src}/site_aggregates.rs (96%) rename {lemmy_db/src/aggregates => lemmy_db_aggregates/src}/user_aggregates.rs (97%) rename {lemmy_db => lemmy_db_queries}/Cargo.toml (96%) rename {lemmy_db => lemmy_db_queries}/src/lib.rs (88%) rename {lemmy_db => lemmy_db_queries}/src/source/activity.rs (97%) rename {lemmy_db => lemmy_db_queries}/src/source/category.rs (94%) rename {lemmy_db => lemmy_db_queries}/src/source/comment.rs (98%) rename {lemmy_db => lemmy_db_queries}/src/source/comment_report.rs (100%) rename {lemmy_db => lemmy_db_queries}/src/source/community.rs (92%) rename {lemmy_db => lemmy_db_queries}/src/source/mod.rs (100%) rename {lemmy_db => lemmy_db_queries}/src/source/moderator.rs (99%) rename {lemmy_db => lemmy_db_queries}/src/source/password_reset_request.rs (96%) rename {lemmy_db => lemmy_db_queries}/src/source/post.rs (99%) rename {lemmy_db => lemmy_db_queries}/src/source/post_report.rs (100%) rename {lemmy_db => lemmy_db_queries}/src/source/private_message.rs (98%) rename {lemmy_db => lemmy_db_queries}/src/source/site.rs (100%) rename {lemmy_db => lemmy_db_queries}/src/source/user.rs (99%) rename {lemmy_db => lemmy_db_queries}/src/source/user_mention.rs (98%) create mode 100644 lemmy_db_views/Cargo.toml rename {lemmy_db/src/views => lemmy_db_views/src}/comment_report_view.rs (98%) rename {lemmy_db/src/views => lemmy_db_views/src}/comment_view.rs (98%) rename {lemmy_db/src/views => lemmy_db_views/src}/community/community_follower_view.rs (97%) rename {lemmy_db/src/views => lemmy_db_views/src}/community/community_moderator_view.rs (97%) rename {lemmy_db/src/views => lemmy_db_views/src}/community/community_user_ban_view.rs (97%) rename {lemmy_db/src/views => lemmy_db_views/src}/community/community_view.rs (85%) rename {lemmy_db/src/views => lemmy_db_views/src}/community/mod.rs (100%) rename lemmy_db/src/views/mod.rs => lemmy_db_views/src/lib.rs (100%) rename {lemmy_db/src/views => lemmy_db_views/src}/moderator/mod.rs (100%) rename {lemmy_db/src/views => lemmy_db_views/src}/moderator/mod_add_community_view.rs (97%) rename {lemmy_db/src/views => lemmy_db_views/src}/moderator/mod_add_view.rs (96%) rename {lemmy_db/src/views => lemmy_db_views/src}/moderator/mod_ban_from_community_view.rs (97%) rename {lemmy_db/src/views => lemmy_db_views/src}/moderator/mod_ban_view.rs (96%) rename {lemmy_db/src/views => lemmy_db_views/src}/moderator/mod_lock_post_view.rs (96%) rename {lemmy_db/src/views => lemmy_db_views/src}/moderator/mod_remove_comment_view.rs (97%) rename {lemmy_db/src/views => lemmy_db_views/src}/moderator/mod_remove_community_view.rs (96%) rename {lemmy_db/src/views => lemmy_db_views/src}/moderator/mod_remove_post_view.rs (96%) rename {lemmy_db/src/views => lemmy_db_views/src}/moderator/mod_sticky_post_view.rs (96%) rename {lemmy_db/src/views => lemmy_db_views/src}/post_report_view.rs (98%) rename {lemmy_db/src/views => lemmy_db_views/src}/post_view.rs (98%) rename {lemmy_db/src/views => lemmy_db_views/src}/private_message_view.rs (97%) rename {lemmy_db/src/views => lemmy_db_views/src}/site_view.rs (90%) rename {lemmy_db/src/views => lemmy_db_views/src}/user_mention_view.rs (98%) rename {lemmy_db/src/views => lemmy_db_views/src}/user_view.rs (96%) diff --git a/Cargo.lock b/Cargo.lock index a639b800e..dd16aa97f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1717,8 +1717,9 @@ dependencies = [ "jsonwebtoken", "lazy_static", "lemmy_apub", - "lemmy_db", + "lemmy_db_queries", "lemmy_db_schema", + "lemmy_db_views", "lemmy_rate_limit", "lemmy_structs", "lemmy_utils", @@ -1762,8 +1763,9 @@ dependencies = [ "http-signature-normalization-reqwest", "itertools", "lazy_static", - "lemmy_db", + "lemmy_db_queries", "lemmy_db_schema", + "lemmy_db_views", "lemmy_structs", "lemmy_utils", "lemmy_websocket", @@ -1784,7 +1786,18 @@ dependencies = [ ] [[package]] -name = "lemmy_db" +name = "lemmy_db_aggregates" +version = "0.1.0" +dependencies = [ + "chrono", + "diesel", + "lemmy_db_queries", + "lemmy_db_schema", + "serde 1.0.118", +] + +[[package]] +name = "lemmy_db_queries" version = "0.1.0" dependencies = [ "bcrypt", @@ -1816,6 +1829,17 @@ dependencies = [ "url", ] +[[package]] +name = "lemmy_db_views" +version = "0.1.0" +dependencies = [ + "diesel", + "lemmy_db_aggregates", + "lemmy_db_queries", + "lemmy_db_schema", + "serde 1.0.118", +] + [[package]] name = "lemmy_rate_limit" version = "0.1.0" @@ -1850,8 +1874,10 @@ dependencies = [ "lazy_static", "lemmy_api", "lemmy_apub", - "lemmy_db", + "lemmy_db_aggregates", + "lemmy_db_queries", "lemmy_db_schema", + "lemmy_db_views", "lemmy_rate_limit", "lemmy_structs", "lemmy_utils", @@ -1875,8 +1901,9 @@ dependencies = [ "actix-web", "chrono", "diesel", - "lemmy_db", + "lemmy_db_queries", "lemmy_db_schema", + "lemmy_db_views", "lemmy_utils", "log", "serde 1.0.118", @@ -1917,7 +1944,7 @@ dependencies = [ "background-jobs", "chrono", "diesel", - "lemmy_db", + "lemmy_db_queries", "lemmy_db_schema", "lemmy_rate_limit", "lemmy_structs", diff --git a/Cargo.toml b/Cargo.toml index e77140659..f6234416b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ "lemmy_api", "lemmy_apub", "lemmy_utils", - "lemmy_db", + "lemmy_db_queries", "lemmy_db_schema", "lemmy_structs", "lemmy_rate_limit", @@ -23,7 +23,9 @@ lemmy_api = { path = "./lemmy_api" } lemmy_apub = { path = "./lemmy_apub" } lemmy_utils = { path = "./lemmy_utils" } lemmy_db_schema = { path = "./lemmy_db_schema" } -lemmy_db = { path = "./lemmy_db" } +lemmy_db_queries = { path = "lemmy_db_queries" } +lemmy_db_views = { path = "./lemmy_db_views" } +lemmy_db_aggregates = { path = "./lemmy_db_aggregates" } lemmy_structs = { path = "./lemmy_structs" } lemmy_rate_limit = { path = "./lemmy_rate_limit" } lemmy_websocket = { path = "./lemmy_websocket" } diff --git a/lemmy_api/Cargo.toml b/lemmy_api/Cargo.toml index fc845c118..b9bda5990 100644 --- a/lemmy_api/Cargo.toml +++ b/lemmy_api/Cargo.toml @@ -11,8 +11,9 @@ path = "src/lib.rs" [dependencies] lemmy_apub = { path = "../lemmy_apub" } lemmy_utils = { path = "../lemmy_utils" } -lemmy_db = { path = "../lemmy_db" } +lemmy_db_queries = { path = "../lemmy_db_queries" } lemmy_db_schema = { path = "../lemmy_db_schema" } +lemmy_db_views = { path = "../lemmy_db_views" } lemmy_structs = { path = "../lemmy_structs" } lemmy_rate_limit = { path = "../lemmy_rate_limit" } lemmy_websocket = { path = "../lemmy_websocket" } diff --git a/lemmy_api/src/comment.rs b/lemmy_api/src/comment.rs index bafde6bfb..eb8d68b7c 100644 --- a/lemmy_api/src/comment.rs +++ b/lemmy_api/src/comment.rs @@ -12,10 +12,6 @@ use actix_web::web::Data; use lemmy_apub::{ApubLikeableType, ApubObjectType}; use lemmy_db::{ source::comment::Comment_, - views::{ - comment_report_view::{CommentReportQueryBuilder, CommentReportView}, - comment_view::{CommentQueryBuilder, CommentView}, - }, Crud, Likeable, ListingType, @@ -24,6 +20,10 @@ use lemmy_db::{ SortType, }; use lemmy_db_schema::source::{comment::*, comment_report::*, moderator::*}; +use lemmy_db_views::{ + comment_report_view::{CommentReportQueryBuilder, CommentReportView}, + comment_view::{CommentQueryBuilder, CommentView}, +}; use lemmy_structs::{blocking, comment::*, send_local_notifs}; use lemmy_utils::{ apub::{make_apub_endpoint, EndpointType}, diff --git a/lemmy_api/src/community.rs b/lemmy_api/src/community.rs index 405491bd2..8c2d9ad5a 100644 --- a/lemmy_api/src/community.rs +++ b/lemmy_api/src/community.rs @@ -16,15 +16,6 @@ use lemmy_db::{ community::{CommunityModerator_, Community_}, post::Post_, }, - views::{ - comment_view::CommentQueryBuilder, - community::{ - community_follower_view::CommunityFollowerView, - community_moderator_view::CommunityModeratorView, - community_view::{CommunityQueryBuilder, CommunityView}, - }, - user_view::UserViewSafe, - }, ApubObject, Bannable, Crud, @@ -36,6 +27,15 @@ use lemmy_db_schema::{ naive_now, source::{comment::Comment, community::*, moderator::*, post::Post, site::*}, }; +use lemmy_db_views::{ + comment_view::CommentQueryBuilder, + community::{ + community_follower_view::CommunityFollowerView, + community_moderator_view::CommunityModeratorView, + community_view::{CommunityQueryBuilder, CommunityView}, + }, + user_view::UserViewSafe, +}; use lemmy_structs::{blocking, community::*}; use lemmy_utils::{ apub::{generate_actor_keypair, make_apub_endpoint, EndpointType}, diff --git a/lemmy_api/src/lib.rs b/lemmy_api/src/lib.rs index 4b61539b4..72c2316de 100644 --- a/lemmy_api/src/lib.rs +++ b/lemmy_api/src/lib.rs @@ -5,7 +5,6 @@ use lemmy_db::{ community::{CommunityModerator_, Community_}, site::Site_, }, - views::community::community_user_ban_view::CommunityUserBanView, Crud, DbPool, }; @@ -15,6 +14,10 @@ use lemmy_db_schema::source::{ site::Site, user::User_, }; +use lemmy_db_views::community::{ + community_user_ban_view::CommunityUserBanView, + community_view::CommunityView, +}; use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*}; use lemmy_utils::{settings::Settings, APIError, ConnectionId, LemmyError}; use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation}; @@ -47,7 +50,7 @@ pub(crate) async fn is_mod_or_admin( community_id: i32, ) -> Result<(), LemmyError> { let is_mod_or_admin = blocking(pool, move |conn| { - Community::is_mod_or_admin(conn, user_id, community_id) + CommunityView::is_mod_or_admin(conn, user_id, community_id) }) .await?; if !is_mod_or_admin { diff --git a/lemmy_api/src/post.rs b/lemmy_api/src/post.rs index 20b5b8d55..6f5149702 100644 --- a/lemmy_api/src/post.rs +++ b/lemmy_api/src/post.rs @@ -10,21 +10,7 @@ use crate::{ }; use actix_web::web::Data; use lemmy_apub::{ApubLikeableType, ApubObjectType}; -use lemmy_db::{ - source::post::Post_, - views::{ - comment_view::CommentQueryBuilder, - community::community_moderator_view::CommunityModeratorView, - post_report_view::{PostReportQueryBuilder, PostReportView}, - post_view::{PostQueryBuilder, PostView}, - }, - Crud, - Likeable, - ListingType, - Reportable, - Saveable, - SortType, -}; +use lemmy_db::{source::post::Post_, Crud, Likeable, ListingType, Reportable, Saveable, SortType}; use lemmy_db_schema::{ naive_now, source::{ @@ -33,6 +19,12 @@ use lemmy_db_schema::{ post_report::{PostReport, PostReportForm}, }, }; +use lemmy_db_views::{ + comment_view::CommentQueryBuilder, + community::community_moderator_view::CommunityModeratorView, + post_report_view::{PostReportQueryBuilder, PostReportView}, + post_view::{PostQueryBuilder, PostView}, +}; use lemmy_structs::{blocking, post::*}; use lemmy_utils::{ apub::{make_apub_endpoint, EndpointType}, diff --git a/lemmy_api/src/site.rs b/lemmy_api/src/site.rs index e30e62303..dcf35c007 100644 --- a/lemmy_api/src/site.rs +++ b/lemmy_api/src/site.rs @@ -12,24 +12,6 @@ use lemmy_apub::fetcher::search_by_apub_id; use lemmy_db::{ diesel_option_overwrite, source::{category::Category_, site::Site_}, - views::{ - comment_view::CommentQueryBuilder, - community::community_view::CommunityQueryBuilder, - moderator::{ - mod_add_community_view::ModAddCommunityView, - mod_add_view::ModAddView, - mod_ban_from_community_view::ModBanFromCommunityView, - mod_ban_view::ModBanView, - mod_lock_post_view::ModLockPostView, - mod_remove_comment_view::ModRemoveCommentView, - mod_remove_community_view::ModRemoveCommunityView, - mod_remove_post_view::ModRemovePostView, - mod_sticky_post_view::ModStickyPostView, - }, - post_view::PostQueryBuilder, - site_view::SiteView, - user_view::{UserQueryBuilder, UserViewSafe}, - }, Crud, SearchType, SortType, @@ -42,6 +24,24 @@ use lemmy_db_schema::{ site::{Site, *}, }, }; +use lemmy_db_views::{ + comment_view::CommentQueryBuilder, + community::community_view::CommunityQueryBuilder, + moderator::{ + mod_add_community_view::ModAddCommunityView, + mod_add_view::ModAddView, + mod_ban_from_community_view::ModBanFromCommunityView, + mod_ban_view::ModBanView, + mod_lock_post_view::ModLockPostView, + mod_remove_comment_view::ModRemoveCommentView, + mod_remove_community_view::ModRemoveCommunityView, + mod_remove_post_view::ModRemovePostView, + mod_sticky_post_view::ModStickyPostView, + }, + post_view::PostQueryBuilder, + site_view::SiteView, + user_view::{UserQueryBuilder, UserViewSafe}, +}; use lemmy_structs::{blocking, site::*, user::Register}; use lemmy_utils::{ location_info, diff --git a/lemmy_api/src/user.rs b/lemmy_api/src/user.rs index 34ef5022e..908911546 100644 --- a/lemmy_api/src/user.rs +++ b/lemmy_api/src/user.rs @@ -26,19 +26,6 @@ use lemmy_db::{ user::User, user_mention::UserMention_, }, - views::{ - comment_report_view::CommentReportView, - comment_view::CommentQueryBuilder, - community::{ - community_follower_view::CommunityFollowerView, - community_moderator_view::CommunityModeratorView, - }, - post_report_view::PostReportView, - post_view::PostQueryBuilder, - private_message_view::{PrivateMessageQueryBuilder, PrivateMessageView}, - user_mention_view::{UserMentionQueryBuilder, UserMentionView}, - user_view::{UserViewDangerous, UserViewSafe}, - }, Crud, Followable, Joinable, @@ -59,6 +46,19 @@ use lemmy_db_schema::{ user_mention::*, }, }; +use lemmy_db_views::{ + comment_report_view::CommentReportView, + comment_view::CommentQueryBuilder, + community::{ + community_follower_view::CommunityFollowerView, + community_moderator_view::CommunityModeratorView, + }, + post_report_view::PostReportView, + post_view::PostQueryBuilder, + private_message_view::{PrivateMessageQueryBuilder, PrivateMessageView}, + user_mention_view::{UserMentionQueryBuilder, UserMentionView}, + user_view::{UserViewDangerous, UserViewSafe}, +}; use lemmy_structs::{blocking, send_email_to_user, user::*}; use lemmy_utils::{ apub::{generate_actor_keypair, make_apub_endpoint, EndpointType}, diff --git a/lemmy_apub/Cargo.toml b/lemmy_apub/Cargo.toml index 09dd9be83..a912f4487 100644 --- a/lemmy_apub/Cargo.toml +++ b/lemmy_apub/Cargo.toml @@ -10,8 +10,9 @@ path = "src/lib.rs" [dependencies] lemmy_utils = { path = "../lemmy_utils" } -lemmy_db = { path = "../lemmy_db" } +lemmy_db_queries = { path = "../lemmy_db_queries" } lemmy_db_schema = { path = "../lemmy_db_schema" } +lemmy_db_views = { path = "../lemmy_db_views" } lemmy_structs = { path = "../lemmy_structs" } lemmy_websocket = { path = "../lemmy_websocket" } diesel = "1.4.5" diff --git a/lemmy_apub/src/activities/receive/comment.rs b/lemmy_apub/src/activities/receive/comment.rs index 0149e9313..483ef54fe 100644 --- a/lemmy_apub/src/activities/receive/comment.rs +++ b/lemmy_apub/src/activities/receive/comment.rs @@ -4,11 +4,12 @@ use activitystreams::{ base::ExtendsExt, }; use anyhow::Context; -use lemmy_db::{source::comment::Comment_, views::comment_view::CommentView, Crud, Likeable}; +use lemmy_db::{source::comment::Comment_, Crud, Likeable}; use lemmy_db_schema::source::{ comment::{Comment, CommentLike, CommentLikeForm}, post::Post, }; +use lemmy_db_views::comment_view::CommentView; use lemmy_structs::{blocking, comment::CommentResponse, send_local_notifs}; use lemmy_utils::{location_info, utils::scrape_text_for_mentions, LemmyError}; use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation}; diff --git a/lemmy_apub/src/activities/receive/comment_undo.rs b/lemmy_apub/src/activities/receive/comment_undo.rs index 7e6720457..4f845523d 100644 --- a/lemmy_apub/src/activities/receive/comment_undo.rs +++ b/lemmy_apub/src/activities/receive/comment_undo.rs @@ -1,7 +1,8 @@ use crate::activities::receive::get_actor_as_user; use activitystreams::activity::{Dislike, Like}; -use lemmy_db::{source::comment::Comment_, views::comment_view::CommentView, Likeable}; +use lemmy_db::{source::comment::Comment_, Likeable}; use lemmy_db_schema::source::comment::{Comment, CommentLike}; +use lemmy_db_views::comment_view::CommentView; use lemmy_structs::{blocking, comment::CommentResponse}; use lemmy_utils::LemmyError; use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation}; diff --git a/lemmy_apub/src/activities/receive/community.rs b/lemmy_apub/src/activities/receive/community.rs index 932917b1e..f493a5632 100644 --- a/lemmy_apub/src/activities/receive/community.rs +++ b/lemmy_apub/src/activities/receive/community.rs @@ -4,12 +4,9 @@ use activitystreams::{ base::{AnyBase, ExtendsExt}, }; use anyhow::Context; -use lemmy_db::{ - source::community::Community_, - views::community::community_view::CommunityView, - ApubObject, -}; +use lemmy_db::{source::community::Community_, ApubObject}; use lemmy_db_schema::source::community::Community; +use lemmy_db_views::community::community_view::CommunityView; use lemmy_structs::{blocking, community::CommunityResponse}; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation}; diff --git a/lemmy_apub/src/activities/receive/post.rs b/lemmy_apub/src/activities/receive/post.rs index 8e20da75f..2b46cf54a 100644 --- a/lemmy_apub/src/activities/receive/post.rs +++ b/lemmy_apub/src/activities/receive/post.rs @@ -4,8 +4,9 @@ use activitystreams::{ prelude::*, }; use anyhow::Context; -use lemmy_db::{source::post::Post_, views::post_view::PostView, Likeable}; +use lemmy_db::{source::post::Post_, Likeable}; use lemmy_db_schema::source::post::{Post, PostLike, PostLikeForm}; +use lemmy_db_views::post_view::PostView; use lemmy_structs::{blocking, post::PostResponse}; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation}; diff --git a/lemmy_apub/src/activities/receive/post_undo.rs b/lemmy_apub/src/activities/receive/post_undo.rs index facaf65f1..bf188a9f6 100644 --- a/lemmy_apub/src/activities/receive/post_undo.rs +++ b/lemmy_apub/src/activities/receive/post_undo.rs @@ -1,7 +1,8 @@ use crate::activities::receive::get_actor_as_user; use activitystreams::activity::{Dislike, Like}; -use lemmy_db::{source::post::Post_, views::post_view::PostView, Likeable}; +use lemmy_db::{source::post::Post_, Likeable}; use lemmy_db_schema::source::post::{Post, PostLike}; +use lemmy_db_views::post_view::PostView; use lemmy_structs::{blocking, post::PostResponse}; use lemmy_utils::LemmyError; use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation}; diff --git a/lemmy_apub/src/activities/receive/private_message.rs b/lemmy_apub/src/activities/receive/private_message.rs index 09c234cac..d2755094a 100644 --- a/lemmy_apub/src/activities/receive/private_message.rs +++ b/lemmy_apub/src/activities/receive/private_message.rs @@ -13,11 +13,9 @@ use activitystreams::{ public, }; use anyhow::{anyhow, Context}; -use lemmy_db::{ - source::private_message::PrivateMessage_, - views::private_message_view::PrivateMessageView, -}; +use lemmy_db::source::private_message::PrivateMessage_; use lemmy_db_schema::source::private_message::PrivateMessage; +use lemmy_db_views::private_message_view::PrivateMessageView; use lemmy_structs::{blocking, user::PrivateMessageResponse}; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::{messages::SendUserRoomMessage, LemmyContext, UserOperation}; diff --git a/lemmy_apub/src/activities/send/community.rs b/lemmy_apub/src/activities/send/community.rs index 035a8dfed..1a4a4a572 100644 --- a/lemmy_apub/src/activities/send/community.rs +++ b/lemmy_apub/src/activities/send/community.rs @@ -23,8 +23,9 @@ use activitystreams::{ }; use anyhow::Context; use itertools::Itertools; -use lemmy_db::{views::community::community_follower_view::CommunityFollowerView, DbPool}; +use lemmy_db::DbPool; use lemmy_db_schema::source::community::Community; +use lemmy_db_views::community::community_follower_view::CommunityFollowerView; use lemmy_structs::blocking; use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/fetcher.rs b/lemmy_apub/src/fetcher.rs index 608302fab..e67fbc969 100644 --- a/lemmy_apub/src/fetcher.rs +++ b/lemmy_apub/src/fetcher.rs @@ -12,19 +12,7 @@ use activitystreams::{base::BaseExt, collection::OrderedCollection, prelude::*}; use anyhow::{anyhow, Context}; use chrono::NaiveDateTime; use diesel::result::Error::NotFound; -use lemmy_db::{ - source::user::User, - views::{ - comment_view::CommentView, - community::community_view::CommunityView, - post_view::PostView, - user_view::UserViewSafe, - }, - ApubObject, - Crud, - Joinable, - SearchType, -}; +use lemmy_db::{source::user::User, ApubObject, Crud, Joinable, SearchType}; use lemmy_db_schema::{ naive_now, source::{ @@ -34,6 +22,12 @@ use lemmy_db_schema::{ user::User_, }, }; +use lemmy_db_views::{ + comment_view::CommentView, + community::community_view::CommunityView, + post_view::PostView, + user_view::UserViewSafe, +}; use lemmy_structs::{blocking, site::SearchResponse}; use lemmy_utils::{ location_info, diff --git a/lemmy_apub/src/http/community.rs b/lemmy_apub/src/http/community.rs index 45c576d24..011f2d889 100644 --- a/lemmy_apub/src/http/community.rs +++ b/lemmy_apub/src/http/community.rs @@ -9,11 +9,9 @@ use activitystreams::{ collection::{CollectionExt, OrderedCollection, UnorderedCollection}, }; use actix_web::{body::Body, web, HttpResponse}; -use lemmy_db::{ - source::{community::Community_, post::Post_}, - views::community::community_follower_view::CommunityFollowerView, -}; +use lemmy_db::source::{community::Community_, post::Post_}; use lemmy_db_schema::source::{community::Community, post::Post}; +use lemmy_db_views::community::community_follower_view::CommunityFollowerView; use lemmy_structs::blocking; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/inbox/community_inbox.rs b/lemmy_apub/src/inbox/community_inbox.rs index f82da236b..e6d7b29c7 100644 --- a/lemmy_apub/src/inbox/community_inbox.rs +++ b/lemmy_apub/src/inbox/community_inbox.rs @@ -26,17 +26,12 @@ use activitystreams::{ }; use actix_web::{web, HttpRequest, HttpResponse}; use anyhow::{anyhow, Context}; -use lemmy_db::{ - source::community::Community_, - views::community::community_user_ban_view::CommunityUserBanView, - ApubObject, - DbPool, - Followable, -}; +use lemmy_db::{source::community::Community_, ApubObject, DbPool, Followable}; use lemmy_db_schema::source::{ community::{Community, CommunityFollower, CommunityFollowerForm}, user::User_, }; +use lemmy_db_views::community::community_user_ban_view::CommunityUserBanView; use lemmy_structs::blocking; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/objects/community.rs b/lemmy_apub/src/objects/community.rs index b408f7737..f4910716a 100644 --- a/lemmy_apub/src/objects/community.rs +++ b/lemmy_apub/src/objects/community.rs @@ -22,11 +22,12 @@ use activitystreams::{ }; use activitystreams_ext::Ext2; use anyhow::Context; -use lemmy_db::{views::community::community_moderator_view::CommunityModeratorView, DbPool}; +use lemmy_db::DbPool; use lemmy_db_schema::{ naive_now, source::community::{Community, CommunityForm}, }; +use lemmy_db_views::community::community_moderator_view::CommunityModeratorView; use lemmy_structs::blocking; use lemmy_utils::{ location_info, diff --git a/lemmy_db_aggregates/Cargo.toml b/lemmy_db_aggregates/Cargo.toml new file mode 100644 index 000000000..6fdd77fde --- /dev/null +++ b/lemmy_db_aggregates/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "lemmy_db_aggregates" +version = "0.1.0" +edition = "2018" + +[dependencies] +lemmy_db_schema = { path = "../lemmy_db_schema" } +lemmy_db_queries = { path = "../lemmy_db_queries" } +diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] } +serde = { version = "1.0.118", features = ["derive"] } +chrono = { version = "0.4.19", features = ["serde"] } diff --git a/lemmy_db/src/aggregates/comment_aggregates.rs b/lemmy_db_aggregates/src/comment_aggregates.rs similarity index 94% rename from lemmy_db/src/aggregates/comment_aggregates.rs rename to lemmy_db_aggregates/src/comment_aggregates.rs index c6b726755..611ec287c 100644 --- a/lemmy_db/src/aggregates/comment_aggregates.rs +++ b/lemmy_db_aggregates/src/comment_aggregates.rs @@ -22,19 +22,13 @@ impl CommentAggregates { #[cfg(test)] mod tests { - use crate::{ - aggregates::comment_aggregates::CommentAggregates, - source::{ - comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, - community::{Community, CommunityForm}, - post::{Post, PostForm}, - user::{UserForm, User_}, - }, - tests::establish_unpooled_connection, - Crud, - Likeable, - ListingType, - SortType, + use crate::comment_aggregates::CommentAggregates; + use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType}; + use lemmy_db_schema::source::{ + comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, + community::{Community, CommunityForm}, + post::{Post, PostForm}, + user::{UserForm, User_}, }; #[test] diff --git a/lemmy_db/src/aggregates/community_aggregates.rs b/lemmy_db_aggregates/src/community_aggregates.rs similarity index 97% rename from lemmy_db/src/aggregates/community_aggregates.rs rename to lemmy_db_aggregates/src/community_aggregates.rs index 229652f00..d6491546c 100644 --- a/lemmy_db/src/aggregates/community_aggregates.rs +++ b/lemmy_db_aggregates/src/community_aggregates.rs @@ -22,14 +22,8 @@ impl CommunityAggregates { #[cfg(test)] mod tests { - use crate::{ - aggregates::community_aggregates::CommunityAggregates, - tests::establish_unpooled_connection, - Crud, - Followable, - ListingType, - SortType, - }; + use crate::community_aggregates::CommunityAggregates; + use lemmy_db::{establish_unpooled_connection, Crud, Followable, ListingType, SortType}; use lemmy_db_schema::source::{ comment::{Comment, CommentForm}, community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm}, diff --git a/lemmy_db/src/aggregates/mod.rs b/lemmy_db_aggregates/src/lib.rs similarity index 100% rename from lemmy_db/src/aggregates/mod.rs rename to lemmy_db_aggregates/src/lib.rs diff --git a/lemmy_db/src/aggregates/post_aggregates.rs b/lemmy_db_aggregates/src/post_aggregates.rs similarity index 97% rename from lemmy_db/src/aggregates/post_aggregates.rs rename to lemmy_db_aggregates/src/post_aggregates.rs index 01082ca06..e2d914085 100644 --- a/lemmy_db/src/aggregates/post_aggregates.rs +++ b/lemmy_db_aggregates/src/post_aggregates.rs @@ -24,14 +24,8 @@ impl PostAggregates { #[cfg(test)] mod tests { - use crate::{ - aggregates::post_aggregates::PostAggregates, - tests::establish_unpooled_connection, - Crud, - Likeable, - ListingType, - SortType, - }; + use crate::post_aggregates::PostAggregates; + use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType}; use lemmy_db_schema::source::{ comment::{Comment, CommentForm}, community::{Community, CommunityForm}, diff --git a/lemmy_db/src/aggregates/site_aggregates.rs b/lemmy_db_aggregates/src/site_aggregates.rs similarity index 96% rename from lemmy_db/src/aggregates/site_aggregates.rs rename to lemmy_db_aggregates/src/site_aggregates.rs index 70997a66a..559c5b53d 100644 --- a/lemmy_db/src/aggregates/site_aggregates.rs +++ b/lemmy_db_aggregates/src/site_aggregates.rs @@ -21,17 +21,13 @@ impl SiteAggregates { #[cfg(test)] mod tests { - use crate::{ - aggregates::site_aggregates::SiteAggregates, - tests::establish_unpooled_connection, - Crud, - ListingType, - SortType, - }; + use crate::site_aggregates::SiteAggregates; + use lemmy_db::{establish_unpooled_connection, Crud, ListingType, SortType}; use lemmy_db_schema::source::{ comment::{Comment, CommentForm}, community::{Community, CommunityForm}, post::{Post, PostForm}, + site::{Site, SiteForm}, user::{UserForm, User_}, }; diff --git a/lemmy_db/src/aggregates/user_aggregates.rs b/lemmy_db_aggregates/src/user_aggregates.rs similarity index 97% rename from lemmy_db/src/aggregates/user_aggregates.rs rename to lemmy_db_aggregates/src/user_aggregates.rs index e8981fd62..cf5dfe69e 100644 --- a/lemmy_db/src/aggregates/user_aggregates.rs +++ b/lemmy_db_aggregates/src/user_aggregates.rs @@ -23,14 +23,8 @@ impl UserAggregates { #[cfg(test)] mod tests { - use crate::{ - aggregates::user_aggregates::UserAggregates, - tests::establish_unpooled_connection, - Crud, - Likeable, - ListingType, - SortType, - }; + use crate::user_aggregates::UserAggregates; + use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType}; use lemmy_db_schema::source::{ comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, community::{Community, CommunityForm}, diff --git a/lemmy_db/Cargo.toml b/lemmy_db_queries/Cargo.toml similarity index 96% rename from lemmy_db/Cargo.toml rename to lemmy_db_queries/Cargo.toml index 15dd749ac..eb633c7d1 100644 --- a/lemmy_db/Cargo.toml +++ b/lemmy_db_queries/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "lemmy_db" +name = "lemmy_db_queries" version = "0.1.0" edition = "2018" diff --git a/lemmy_db/src/lib.rs b/lemmy_db_queries/src/lib.rs similarity index 88% rename from lemmy_db/src/lib.rs rename to lemmy_db_queries/src/lib.rs index 8e3521478..6f4c62c7f 100644 --- a/lemmy_db/src/lib.rs +++ b/lemmy_db_queries/src/lib.rs @@ -14,9 +14,7 @@ use regex::Regex; use serde::{Deserialize, Serialize}; use std::{env, env::VarError}; -pub mod aggregates; pub mod source; -pub mod views; pub type DbPool = diesel::r2d2::Pool>; @@ -133,7 +131,7 @@ impl MaybeOptional for Option { } } -pub(crate) trait ToSafe { +pub trait ToSafe { type SafeColumns; fn safe_columns_tuple() -> Self::SafeColumns; } @@ -202,12 +200,28 @@ pub fn diesel_option_overwrite(opt: &Option) -> Option> { } } +embed_migrations!(); + +pub fn establish_unpooled_connection() -> PgConnection { + let db_url = match get_database_url_from_env() { + Ok(url) => url, + Err(e) => panic!( + "Failed to read database URL from env var LEMMY_DATABASE_URL: {}", + e + ), + }; + let conn = + PgConnection::establish(&db_url).unwrap_or_else(|_| panic!("Error connecting to {}", db_url)); + embedded_migrations::run(&conn).unwrap(); + conn +} + lazy_static! { static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap(); } -pub(crate) mod functions { +pub mod functions { use diesel::sql_types::*; sql_function! { @@ -218,24 +232,7 @@ pub(crate) mod functions { #[cfg(test)] mod tests { use super::fuzzy_search; - use crate::{get_database_url_from_env, is_email_regex}; - use diesel::{Connection, PgConnection}; - - embed_migrations!(); - - pub fn establish_unpooled_connection() -> PgConnection { - let db_url = match get_database_url_from_env() { - Ok(url) => url, - Err(e) => panic!( - "Failed to read database URL from env var LEMMY_DATABASE_URL: {}", - e - ), - }; - let conn = - PgConnection::establish(&db_url).unwrap_or_else(|_| panic!("Error connecting to {}", db_url)); - embedded_migrations::run(&conn).unwrap(); - conn - } + use crate::is_email_regex; #[test] fn test_fuzzy_search() { diff --git a/lemmy_db/src/source/activity.rs b/lemmy_db_queries/src/source/activity.rs similarity index 97% rename from lemmy_db/src/source/activity.rs rename to lemmy_db_queries/src/source/activity.rs index d63b3b6bf..662db3aed 100644 --- a/lemmy_db/src/source/activity.rs +++ b/lemmy_db_queries/src/source/activity.rs @@ -87,7 +87,13 @@ impl Activity_ for Activity { #[cfg(test)] mod tests { - use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType}; + use crate::{ + establish_unpooled_connection, + source::activity::Activity_, + Crud, + ListingType, + SortType, + }; use lemmy_db_schema::source::{ activity::{Activity, ActivityForm}, user::{UserForm, User_}, diff --git a/lemmy_db/src/source/category.rs b/lemmy_db_queries/src/source/category.rs similarity index 94% rename from lemmy_db/src/source/category.rs rename to lemmy_db_queries/src/source/category.rs index c190ddf8f..2d9eeb37b 100644 --- a/lemmy_db/src/source/category.rs +++ b/lemmy_db_queries/src/source/category.rs @@ -36,7 +36,7 @@ impl Category_ for Category { #[cfg(test)] mod tests { - use crate::tests::establish_unpooled_connection; + use crate::{establish_unpooled_connection, source::category::Category_}; use lemmy_db_schema::source::category::Category; #[test] diff --git a/lemmy_db/src/source/comment.rs b/lemmy_db_queries/src/source/comment.rs similarity index 98% rename from lemmy_db/src/source/comment.rs rename to lemmy_db_queries/src/source/comment.rs index d70d7b699..6e99bf36e 100644 --- a/lemmy_db/src/source/comment.rs +++ b/lemmy_db_queries/src/source/comment.rs @@ -204,14 +204,7 @@ impl Saveable for CommentSaved { #[cfg(test)] mod tests { - use crate::{ - tests::establish_unpooled_connection, - Crud, - Likeable, - ListingType, - Saveable, - SortType, - }; + use crate::{establish_unpooled_connection, Crud, Likeable, ListingType, Saveable, SortType}; use lemmy_db_schema::source::{ comment::*, community::{Community, CommunityForm}, diff --git a/lemmy_db/src/source/comment_report.rs b/lemmy_db_queries/src/source/comment_report.rs similarity index 100% rename from lemmy_db/src/source/comment_report.rs rename to lemmy_db_queries/src/source/comment_report.rs diff --git a/lemmy_db/src/source/community.rs b/lemmy_db_queries/src/source/community.rs similarity index 92% rename from lemmy_db/src/source/community.rs rename to lemmy_db_queries/src/source/community.rs index 9a30ca4cd..28245d8dc 100644 --- a/lemmy_db/src/source/community.rs +++ b/lemmy_db_queries/src/source/community.rs @@ -1,11 +1,4 @@ -use crate::{ - views::{community::community_moderator_view::CommunityModeratorView, user_view::UserViewSafe}, - ApubObject, - Bannable, - Crud, - Followable, - Joinable, -}; +use crate::{ApubObject, Bannable, Crud, Followable, Joinable}; use diesel::{dsl::*, result::Error, *}; use lemmy_db_schema::{ naive_now, @@ -138,9 +131,7 @@ pub trait Community_ { community_id: i32, new_creator_id: i32, ) -> Result; - fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result, Error>; fn distinct_federated_communities(conn: &PgConnection) -> Result, Error>; - fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool; } impl Community_ for Community { @@ -196,27 +187,10 @@ impl Community_ for Community { .get_result::(conn) } - fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result, Error> { - let mut mods_and_admins: Vec = Vec::new(); - mods_and_admins.append( - &mut CommunityModeratorView::for_community(conn, community_id) - .map(|v| v.into_iter().map(|m| m.moderator.id).collect())?, - ); - mods_and_admins - .append(&mut UserViewSafe::admins(conn).map(|v| v.into_iter().map(|a| a.user.id).collect())?); - Ok(mods_and_admins) - } - fn distinct_federated_communities(conn: &PgConnection) -> Result, Error> { use lemmy_db_schema::schema::community::dsl::*; community.select(actor_id).distinct().load::(conn) } - - fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool { - Self::community_mods_and_admins(conn, community_id) - .unwrap_or_default() - .contains(&user_id) - } } impl Joinable for CommunityModerator { @@ -347,7 +321,7 @@ impl Followable for CommunityFollower { #[cfg(test)] mod tests { use crate::{ - tests::establish_unpooled_connection, + establish_unpooled_connection, Bannable, Crud, Followable, diff --git a/lemmy_db/src/source/mod.rs b/lemmy_db_queries/src/source/mod.rs similarity index 100% rename from lemmy_db/src/source/mod.rs rename to lemmy_db_queries/src/source/mod.rs diff --git a/lemmy_db/src/source/moderator.rs b/lemmy_db_queries/src/source/moderator.rs similarity index 99% rename from lemmy_db/src/source/moderator.rs rename to lemmy_db_queries/src/source/moderator.rs index b0a17d6d5..93c424164 100644 --- a/lemmy_db/src/source/moderator.rs +++ b/lemmy_db_queries/src/source/moderator.rs @@ -197,7 +197,7 @@ impl Crud for ModAdd { #[cfg(test)] mod tests { - use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType}; + use crate::{establish_unpooled_connection, Crud, ListingType, SortType}; use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, user::*}; // use Crud; diff --git a/lemmy_db/src/source/password_reset_request.rs b/lemmy_db_queries/src/source/password_reset_request.rs similarity index 96% rename from lemmy_db/src/source/password_reset_request.rs rename to lemmy_db_queries/src/source/password_reset_request.rs index 9ca8dab68..d4ba2f12d 100644 --- a/lemmy_db/src/source/password_reset_request.rs +++ b/lemmy_db_queries/src/source/password_reset_request.rs @@ -72,7 +72,13 @@ fn bytes_to_hex(bytes: Vec) -> String { #[cfg(test)] mod tests { - use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType}; + use crate::{ + establish_unpooled_connection, + source::password_reset_request::PasswordResetRequest_, + Crud, + ListingType, + SortType, + }; use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, user::*}; #[test] diff --git a/lemmy_db/src/source/post.rs b/lemmy_db_queries/src/source/post.rs similarity index 99% rename from lemmy_db/src/source/post.rs rename to lemmy_db_queries/src/source/post.rs index c681adbe4..bca848cad 100644 --- a/lemmy_db/src/source/post.rs +++ b/lemmy_db_queries/src/source/post.rs @@ -225,7 +225,7 @@ impl Readable for PostRead { #[cfg(test)] mod tests { - use crate::{source::post::*, tests::establish_unpooled_connection, ListingType, SortType}; + use crate::{establish_unpooled_connection, source::post::*, ListingType, SortType}; use lemmy_db_schema::source::{ community::{Community, CommunityForm}, user::*, diff --git a/lemmy_db/src/source/post_report.rs b/lemmy_db_queries/src/source/post_report.rs similarity index 100% rename from lemmy_db/src/source/post_report.rs rename to lemmy_db_queries/src/source/post_report.rs diff --git a/lemmy_db/src/source/private_message.rs b/lemmy_db_queries/src/source/private_message.rs similarity index 98% rename from lemmy_db/src/source/private_message.rs rename to lemmy_db_queries/src/source/private_message.rs index b49ed8f4f..d63f698d9 100644 --- a/lemmy_db/src/source/private_message.rs +++ b/lemmy_db_queries/src/source/private_message.rs @@ -139,7 +139,13 @@ impl PrivateMessage_ for PrivateMessage { #[cfg(test)] mod tests { - use crate::{tests::establish_unpooled_connection, ListingType, SortType}; + use crate::{ + establish_unpooled_connection, + source::private_message::PrivateMessage_, + Crud, + ListingType, + SortType, + }; use lemmy_db_schema::source::{private_message::*, user::*}; #[test] diff --git a/lemmy_db/src/source/site.rs b/lemmy_db_queries/src/source/site.rs similarity index 100% rename from lemmy_db/src/source/site.rs rename to lemmy_db_queries/src/source/site.rs diff --git a/lemmy_db/src/source/user.rs b/lemmy_db_queries/src/source/user.rs similarity index 99% rename from lemmy_db/src/source/user.rs rename to lemmy_db_queries/src/source/user.rs index 7461f4b45..7789ff2be 100644 --- a/lemmy_db/src/source/user.rs +++ b/lemmy_db_queries/src/source/user.rs @@ -297,7 +297,7 @@ impl User for User_ { #[cfg(test)] mod tests { - use crate::{source::user::*, tests::establish_unpooled_connection, ListingType, SortType}; + use crate::{establish_unpooled_connection, source::user::*, ListingType, SortType}; #[test] fn test_crud() { diff --git a/lemmy_db/src/source/user_mention.rs b/lemmy_db_queries/src/source/user_mention.rs similarity index 98% rename from lemmy_db/src/source/user_mention.rs rename to lemmy_db_queries/src/source/user_mention.rs index 64406f989..d9e0cce30 100644 --- a/lemmy_db/src/source/user_mention.rs +++ b/lemmy_db_queries/src/source/user_mention.rs @@ -73,7 +73,7 @@ impl UserMention_ for UserMention { #[cfg(test)] mod tests { - use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType}; + use crate::{establish_unpooled_connection, Crud, ListingType, SortType}; use lemmy_db_schema::source::{ comment::*, community::{Community, CommunityForm}, diff --git a/lemmy_db_schema/src/lib.rs b/lemmy_db_schema/src/lib.rs index 3868a3b75..981ecba27 100644 --- a/lemmy_db_schema/src/lib.rs +++ b/lemmy_db_schema/src/lib.rs @@ -6,7 +6,7 @@ use chrono::NaiveDateTime; pub mod schema; pub mod source; -// TODO: can probably move this back to lemmy_db +// TODO: can probably move this back to lemmy_db_queries pub fn naive_now() -> NaiveDateTime { chrono::prelude::Utc::now().naive_utc() } diff --git a/lemmy_db_schema/src/source/comment_report.rs b/lemmy_db_schema/src/source/comment_report.rs index ec53408d1..d94fed578 100644 --- a/lemmy_db_schema/src/source/comment_report.rs +++ b/lemmy_db_schema/src/source/comment_report.rs @@ -1,9 +1,7 @@ use crate::{schema::comment_report, source::comment::Comment}; use serde::{Deserialize, Serialize}; -#[derive( - Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone, -)] +#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)] #[belongs_to(Comment)] #[table_name = "comment_report"] pub struct CommentReport { diff --git a/lemmy_db_schema/src/source/post_report.rs b/lemmy_db_schema/src/source/post_report.rs index b75fb954a..608104dbc 100644 --- a/lemmy_db_schema/src/source/post_report.rs +++ b/lemmy_db_schema/src/source/post_report.rs @@ -1,9 +1,7 @@ use crate::{schema::post_report, source::post::Post}; use serde::{Deserialize, Serialize}; -#[derive( - Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone, -)] +#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)] #[belongs_to(Post)] #[table_name = "post_report"] pub struct PostReport { diff --git a/lemmy_db_views/Cargo.toml b/lemmy_db_views/Cargo.toml new file mode 100644 index 000000000..86c7ada15 --- /dev/null +++ b/lemmy_db_views/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "lemmy_db_views" +version = "0.1.0" +edition = "2018" + +[dependencies] +lemmy_db_queries = { path = "../lemmy_db_queries" } +lemmy_db_schema = { path = "../lemmy_db_schema" } +lemmy_db_aggregates = { path = "../lemmy_db_aggregates" } +diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] } +serde = { version = "1.0.118", features = ["derive"] } \ No newline at end of file diff --git a/lemmy_db/src/views/comment_report_view.rs b/lemmy_db_views/src/comment_report_view.rs similarity index 98% rename from lemmy_db/src/views/comment_report_view.rs rename to lemmy_db_views/src/comment_report_view.rs index 7a260cd59..fa795a0bf 100644 --- a/lemmy_db/src/views/comment_report_view.rs +++ b/lemmy_db_views/src/comment_report_view.rs @@ -1,5 +1,6 @@ -use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::{limit_and_offset, MaybeOptional, ToSafe}; use lemmy_db_schema::{ schema::{comment, comment_report, community, post, user_, user_alias_1, user_alias_2}, source::{ diff --git a/lemmy_db/src/views/comment_view.rs b/lemmy_db_views/src/comment_view.rs similarity index 98% rename from lemmy_db/src/views/comment_view.rs rename to lemmy_db_views/src/comment_view.rs index 1b114e190..3101fcea8 100644 --- a/lemmy_db/src/views/comment_view.rs +++ b/lemmy_db_views/src/comment_view.rs @@ -1,15 +1,15 @@ -use crate::{ - aggregates::comment_aggregates::CommentAggregates, +use crate::ViewToVec; +use diesel::{result::Error, *}; +use lemmy_db::{ functions::hot_rank, fuzzy_search, limit_and_offset, - views::ViewToVec, ListingType, MaybeOptional, SortType, ToSafe, }; -use diesel::{result::Error, *}; +use lemmy_db_aggregates::comment_aggregates::CommentAggregates; use lemmy_db_schema::{ schema::{ comment, @@ -418,7 +418,9 @@ impl ViewToVec for CommentView { #[cfg(test)] mod tests { - use crate::{tests::establish_unpooled_connection, views::comment_view::*, Crud, Likeable, *}; + use crate::comment_view::*; + use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType}; + use lemmy_db_aggregates::comment_aggregates::CommentAggregates; use lemmy_db_schema::source::{comment::*, community::*, post::*, user::*}; #[test] diff --git a/lemmy_db/src/views/community/community_follower_view.rs b/lemmy_db_views/src/community/community_follower_view.rs similarity index 97% rename from lemmy_db/src/views/community/community_follower_view.rs rename to lemmy_db_views/src/community/community_follower_view.rs index e7ba0e4a6..9837624cb 100644 --- a/lemmy_db/src/views/community/community_follower_view.rs +++ b/lemmy_db_views/src/community/community_follower_view.rs @@ -1,5 +1,6 @@ -use crate::{views::ViewToVec, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::ToSafe; use lemmy_db_schema::{ schema::{community, community_follower, user_}, source::{ diff --git a/lemmy_db/src/views/community/community_moderator_view.rs b/lemmy_db_views/src/community/community_moderator_view.rs similarity index 97% rename from lemmy_db/src/views/community/community_moderator_view.rs rename to lemmy_db_views/src/community/community_moderator_view.rs index 6800853ea..490105d8b 100644 --- a/lemmy_db/src/views/community/community_moderator_view.rs +++ b/lemmy_db_views/src/community/community_moderator_view.rs @@ -1,5 +1,6 @@ -use crate::{views::ViewToVec, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::ToSafe; use lemmy_db_schema::{ schema::{community, community_moderator, user_}, source::{ diff --git a/lemmy_db/src/views/community/community_user_ban_view.rs b/lemmy_db_views/src/community/community_user_ban_view.rs similarity index 97% rename from lemmy_db/src/views/community/community_user_ban_view.rs rename to lemmy_db_views/src/community/community_user_ban_view.rs index 1c26ebcf1..ddc902766 100644 --- a/lemmy_db/src/views/community/community_user_ban_view.rs +++ b/lemmy_db_views/src/community/community_user_ban_view.rs @@ -1,5 +1,5 @@ -use crate::ToSafe; use diesel::{result::Error, *}; +use lemmy_db::ToSafe; use lemmy_db_schema::{ schema::{community, community_user_ban, user_}, source::{ diff --git a/lemmy_db/src/views/community/community_view.rs b/lemmy_db_views/src/community/community_view.rs similarity index 85% rename from lemmy_db/src/views/community/community_view.rs rename to lemmy_db_views/src/community/community_view.rs index 11962d79a..fe87e2c78 100644 --- a/lemmy_db/src/views/community/community_view.rs +++ b/lemmy_db_views/src/community/community_view.rs @@ -1,14 +1,18 @@ use crate::{ - aggregates::community_aggregates::CommunityAggregates, + community::community_moderator_view::CommunityModeratorView, + user_view::UserViewSafe, + ViewToVec, +}; +use diesel::{result::Error, *}; +use lemmy_db::{ functions::hot_rank, fuzzy_search, limit_and_offset, - views::ViewToVec, MaybeOptional, SortType, ToSafe, }; -use diesel::{result::Error, *}; +use lemmy_db_aggregates::community_aggregates::CommunityAggregates; use lemmy_db_schema::{ schema::{category, community, community_aggregates, community_follower, user_}, source::{ @@ -74,6 +78,24 @@ impl CommunityView { counts, }) } + + // TODO: this function is only used by is_mod_or_admin() below, can probably be merged + fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result, Error> { + let mut mods_and_admins: Vec = Vec::new(); + mods_and_admins.append( + &mut CommunityModeratorView::for_community(conn, community_id) + .map(|v| v.into_iter().map(|m| m.moderator.id).collect())?, + ); + mods_and_admins + .append(&mut UserViewSafe::admins(conn).map(|v| v.into_iter().map(|a| a.user.id).collect())?); + Ok(mods_and_admins) + } + + pub fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool { + Self::community_mods_and_admins(conn, community_id) + .unwrap_or_default() + .contains(&user_id) + } } pub struct CommunityQueryBuilder<'a> { diff --git a/lemmy_db/src/views/community/mod.rs b/lemmy_db_views/src/community/mod.rs similarity index 100% rename from lemmy_db/src/views/community/mod.rs rename to lemmy_db_views/src/community/mod.rs diff --git a/lemmy_db/src/views/mod.rs b/lemmy_db_views/src/lib.rs similarity index 100% rename from lemmy_db/src/views/mod.rs rename to lemmy_db_views/src/lib.rs diff --git a/lemmy_db/src/views/moderator/mod.rs b/lemmy_db_views/src/moderator/mod.rs similarity index 100% rename from lemmy_db/src/views/moderator/mod.rs rename to lemmy_db_views/src/moderator/mod.rs diff --git a/lemmy_db/src/views/moderator/mod_add_community_view.rs b/lemmy_db_views/src/moderator/mod_add_community_view.rs similarity index 97% rename from lemmy_db/src/views/moderator/mod_add_community_view.rs rename to lemmy_db_views/src/moderator/mod_add_community_view.rs index 302d37a0b..606ee51e8 100644 --- a/lemmy_db/src/views/moderator/mod_add_community_view.rs +++ b/lemmy_db_views/src/moderator/mod_add_community_view.rs @@ -1,5 +1,6 @@ -use crate::{limit_and_offset, views::ViewToVec, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::{limit_and_offset, ToSafe}; use lemmy_db_schema::{ schema::{community, mod_add_community, user_, user_alias_1}, source::{ diff --git a/lemmy_db/src/views/moderator/mod_add_view.rs b/lemmy_db_views/src/moderator/mod_add_view.rs similarity index 96% rename from lemmy_db/src/views/moderator/mod_add_view.rs rename to lemmy_db_views/src/moderator/mod_add_view.rs index 8f586a6ff..efe33fd3c 100644 --- a/lemmy_db/src/views/moderator/mod_add_view.rs +++ b/lemmy_db_views/src/moderator/mod_add_view.rs @@ -1,5 +1,6 @@ -use crate::{limit_and_offset, views::ViewToVec, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::{limit_and_offset, ToSafe}; use lemmy_db_schema::{ schema::{mod_add, user_, user_alias_1}, source::{ diff --git a/lemmy_db/src/views/moderator/mod_ban_from_community_view.rs b/lemmy_db_views/src/moderator/mod_ban_from_community_view.rs similarity index 97% rename from lemmy_db/src/views/moderator/mod_ban_from_community_view.rs rename to lemmy_db_views/src/moderator/mod_ban_from_community_view.rs index 0ed52dd25..430259a41 100644 --- a/lemmy_db/src/views/moderator/mod_ban_from_community_view.rs +++ b/lemmy_db_views/src/moderator/mod_ban_from_community_view.rs @@ -1,5 +1,6 @@ -use crate::{limit_and_offset, views::ViewToVec, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::{limit_and_offset, ToSafe}; use lemmy_db_schema::{ schema::{community, mod_ban_from_community, user_, user_alias_1}, source::{ diff --git a/lemmy_db/src/views/moderator/mod_ban_view.rs b/lemmy_db_views/src/moderator/mod_ban_view.rs similarity index 96% rename from lemmy_db/src/views/moderator/mod_ban_view.rs rename to lemmy_db_views/src/moderator/mod_ban_view.rs index 98cf1969f..f61a04219 100644 --- a/lemmy_db/src/views/moderator/mod_ban_view.rs +++ b/lemmy_db_views/src/moderator/mod_ban_view.rs @@ -1,5 +1,6 @@ -use crate::{limit_and_offset, views::ViewToVec, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::{limit_and_offset, ToSafe}; use lemmy_db_schema::{ schema::{mod_ban, user_, user_alias_1}, source::{ diff --git a/lemmy_db/src/views/moderator/mod_lock_post_view.rs b/lemmy_db_views/src/moderator/mod_lock_post_view.rs similarity index 96% rename from lemmy_db/src/views/moderator/mod_lock_post_view.rs rename to lemmy_db_views/src/moderator/mod_lock_post_view.rs index dbe81c5c3..11521329e 100644 --- a/lemmy_db/src/views/moderator/mod_lock_post_view.rs +++ b/lemmy_db_views/src/moderator/mod_lock_post_view.rs @@ -1,5 +1,6 @@ -use crate::{limit_and_offset, views::ViewToVec, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::{limit_and_offset, ToSafe}; use lemmy_db_schema::{ schema::{community, mod_lock_post, post, user_}, source::{ diff --git a/lemmy_db/src/views/moderator/mod_remove_comment_view.rs b/lemmy_db_views/src/moderator/mod_remove_comment_view.rs similarity index 97% rename from lemmy_db/src/views/moderator/mod_remove_comment_view.rs rename to lemmy_db_views/src/moderator/mod_remove_comment_view.rs index 04aab30af..0c52be2f9 100644 --- a/lemmy_db/src/views/moderator/mod_remove_comment_view.rs +++ b/lemmy_db_views/src/moderator/mod_remove_comment_view.rs @@ -1,5 +1,6 @@ -use crate::{limit_and_offset, views::ViewToVec, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::{limit_and_offset, ToSafe}; use lemmy_db_schema::{ schema::{comment, community, mod_remove_comment, post, user_, user_alias_1}, source::{ diff --git a/lemmy_db/src/views/moderator/mod_remove_community_view.rs b/lemmy_db_views/src/moderator/mod_remove_community_view.rs similarity index 96% rename from lemmy_db/src/views/moderator/mod_remove_community_view.rs rename to lemmy_db_views/src/moderator/mod_remove_community_view.rs index 37ffe5402..86fcf1954 100644 --- a/lemmy_db/src/views/moderator/mod_remove_community_view.rs +++ b/lemmy_db_views/src/moderator/mod_remove_community_view.rs @@ -1,5 +1,6 @@ -use crate::{limit_and_offset, views::ViewToVec, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::{limit_and_offset, ToSafe}; use lemmy_db_schema::{ schema::{community, mod_remove_community, user_}, source::{ diff --git a/lemmy_db/src/views/moderator/mod_remove_post_view.rs b/lemmy_db_views/src/moderator/mod_remove_post_view.rs similarity index 96% rename from lemmy_db/src/views/moderator/mod_remove_post_view.rs rename to lemmy_db_views/src/moderator/mod_remove_post_view.rs index 21bf1b867..d4332918f 100644 --- a/lemmy_db/src/views/moderator/mod_remove_post_view.rs +++ b/lemmy_db_views/src/moderator/mod_remove_post_view.rs @@ -1,5 +1,6 @@ -use crate::{limit_and_offset, views::ViewToVec, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::{limit_and_offset, ToSafe}; use lemmy_db_schema::{ schema::{community, mod_remove_post, post, user_}, source::{ diff --git a/lemmy_db/src/views/moderator/mod_sticky_post_view.rs b/lemmy_db_views/src/moderator/mod_sticky_post_view.rs similarity index 96% rename from lemmy_db/src/views/moderator/mod_sticky_post_view.rs rename to lemmy_db_views/src/moderator/mod_sticky_post_view.rs index 8512e0793..ec785ce1b 100644 --- a/lemmy_db/src/views/moderator/mod_sticky_post_view.rs +++ b/lemmy_db_views/src/moderator/mod_sticky_post_view.rs @@ -1,5 +1,6 @@ -use crate::{limit_and_offset, views::ViewToVec, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::{limit_and_offset, ToSafe}; use lemmy_db_schema::{ schema::{community, mod_sticky_post, post, user_}, source::{ diff --git a/lemmy_db/src/views/post_report_view.rs b/lemmy_db_views/src/post_report_view.rs similarity index 98% rename from lemmy_db/src/views/post_report_view.rs rename to lemmy_db_views/src/post_report_view.rs index 37d6275cd..3e0ef3d68 100644 --- a/lemmy_db/src/views/post_report_view.rs +++ b/lemmy_db_views/src/post_report_view.rs @@ -1,5 +1,6 @@ -use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::{limit_and_offset, MaybeOptional, ToSafe}; use lemmy_db_schema::{ schema::{community, post, post_report, user_, user_alias_1, user_alias_2}, source::{ diff --git a/lemmy_db/src/views/post_view.rs b/lemmy_db_views/src/post_view.rs similarity index 98% rename from lemmy_db/src/views/post_view.rs rename to lemmy_db_views/src/post_view.rs index 3cfee1b37..fe1159274 100644 --- a/lemmy_db/src/views/post_view.rs +++ b/lemmy_db_views/src/post_view.rs @@ -1,15 +1,15 @@ -use crate::{ - aggregates::post_aggregates::PostAggregates, +use crate::ViewToVec; +use diesel::{result::Error, *}; +use lemmy_db::{ functions::hot_rank, fuzzy_search, limit_and_offset, - views::ViewToVec, ListingType, MaybeOptional, SortType, ToSafe, }; -use diesel::{result::Error, *}; +use lemmy_db_aggregates::post_aggregates::PostAggregates; use lemmy_db_schema::{ schema::{ community, @@ -406,14 +406,9 @@ impl ViewToVec for PostView { #[cfg(test)] mod tests { - use crate::{ - aggregates::post_aggregates::PostAggregates, - tests::establish_unpooled_connection, - views::post_view::{PostQueryBuilder, PostView}, - Crud, - Likeable, - *, - }; + use crate::post_view::{PostQueryBuilder, PostView}; + use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType}; + use lemmy_db_aggregates::post_aggregates::PostAggregates; use lemmy_db_schema::source::{community::*, post::*, user::*}; #[test] diff --git a/lemmy_db/src/views/private_message_view.rs b/lemmy_db_views/src/private_message_view.rs similarity index 97% rename from lemmy_db/src/views/private_message_view.rs rename to lemmy_db_views/src/private_message_view.rs index f439a75d5..62cb78987 100644 --- a/lemmy_db/src/views/private_message_view.rs +++ b/lemmy_db_views/src/private_message_view.rs @@ -1,5 +1,6 @@ -use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::{limit_and_offset, MaybeOptional, ToSafe}; use lemmy_db_schema::{ schema::{private_message, user_, user_alias_1}, source::{ diff --git a/lemmy_db/src/views/site_view.rs b/lemmy_db_views/src/site_view.rs similarity index 90% rename from lemmy_db/src/views/site_view.rs rename to lemmy_db_views/src/site_view.rs index 7772ccdce..a4c533e05 100644 --- a/lemmy_db/src/views/site_view.rs +++ b/lemmy_db_views/src/site_view.rs @@ -1,5 +1,6 @@ -use crate::{aggregates::site_aggregates::SiteAggregates, ToSafe}; use diesel::{result::Error, *}; +use lemmy_db::ToSafe; +use lemmy_db_aggregates::site_aggregates::SiteAggregates; use lemmy_db_schema::{ schema::{site, site_aggregates, user_}, source::{ diff --git a/lemmy_db/src/views/user_mention_view.rs b/lemmy_db_views/src/user_mention_view.rs similarity index 98% rename from lemmy_db/src/views/user_mention_view.rs rename to lemmy_db_views/src/user_mention_view.rs index 2cd1cd3c8..f6afd298a 100644 --- a/lemmy_db/src/views/user_mention_view.rs +++ b/lemmy_db_views/src/user_mention_view.rs @@ -1,13 +1,7 @@ -use crate::{ - aggregates::comment_aggregates::CommentAggregates, - functions::hot_rank, - limit_and_offset, - views::ViewToVec, - MaybeOptional, - SortType, - ToSafe, -}; +use crate::ViewToVec; use diesel::{result::Error, *}; +use lemmy_db::{functions::hot_rank, limit_and_offset, MaybeOptional, SortType, ToSafe}; +use lemmy_db_aggregates::comment_aggregates::CommentAggregates; use lemmy_db_schema::{ schema::{ comment, diff --git a/lemmy_db/src/views/user_view.rs b/lemmy_db_views/src/user_view.rs similarity index 96% rename from lemmy_db/src/views/user_view.rs rename to lemmy_db_views/src/user_view.rs index f3109011e..5e5e7f2c1 100644 --- a/lemmy_db/src/views/user_view.rs +++ b/lemmy_db_views/src/user_view.rs @@ -1,13 +1,7 @@ -use crate::{ - aggregates::user_aggregates::UserAggregates, - fuzzy_search, - limit_and_offset, - views::ViewToVec, - MaybeOptional, - SortType, - ToSafe, -}; +use crate::ViewToVec; use diesel::{dsl::*, result::Error, *}; +use lemmy_db::{fuzzy_search, limit_and_offset, MaybeOptional, SortType, ToSafe}; +use lemmy_db_aggregates::user_aggregates::UserAggregates; use lemmy_db_schema::{ schema::{user_, user_aggregates}, source::user::{UserSafe, User_}, diff --git a/lemmy_structs/Cargo.toml b/lemmy_structs/Cargo.toml index 329ef4139..d4f013b92 100644 --- a/lemmy_structs/Cargo.toml +++ b/lemmy_structs/Cargo.toml @@ -9,7 +9,8 @@ name = "lemmy_structs" path = "src/lib.rs" [dependencies] -lemmy_db = { path = "../lemmy_db" } +lemmy_db_queries = { path = "../lemmy_db_queries" } +lemmy_db_views = { path = "../lemmy_db_views" } lemmy_db_schema = { path = "../lemmy_db_schema" } lemmy_utils = { path = "../lemmy_utils" } serde = { version = "1.0.118", features = ["derive"] } diff --git a/lemmy_structs/src/comment.rs b/lemmy_structs/src/comment.rs index fe65738d8..1e113b366 100644 --- a/lemmy_structs/src/comment.rs +++ b/lemmy_structs/src/comment.rs @@ -1,4 +1,4 @@ -use lemmy_db::views::{comment_report_view::CommentReportView, comment_view::CommentView}; +use lemmy_db_views::{comment_report_view::CommentReportView, comment_view::CommentView}; use serde::{Deserialize, Serialize}; #[derive(Deserialize)] diff --git a/lemmy_structs/src/community.rs b/lemmy_structs/src/community.rs index 65ea0aaaf..74f7a4e42 100644 --- a/lemmy_structs/src/community.rs +++ b/lemmy_structs/src/community.rs @@ -1,4 +1,4 @@ -use lemmy_db::views::{ +use lemmy_db_views::{ community::{ community_follower_view::CommunityFollowerView, community_moderator_view::CommunityModeratorView, diff --git a/lemmy_structs/src/post.rs b/lemmy_structs/src/post.rs index ac29d8f78..5a35fa37e 100644 --- a/lemmy_structs/src/post.rs +++ b/lemmy_structs/src/post.rs @@ -1,4 +1,4 @@ -use lemmy_db::views::{ +use lemmy_db_views::{ comment_view::CommentView, community::community_moderator_view::CommunityModeratorView, post_report_view::PostReportView, diff --git a/lemmy_structs/src/site.rs b/lemmy_structs/src/site.rs index f24d9f49e..fbb295d51 100644 --- a/lemmy_structs/src/site.rs +++ b/lemmy_structs/src/site.rs @@ -1,4 +1,5 @@ -use lemmy_db::views::{ +use lemmy_db_schema::source::{category::*, user::User_}; +use lemmy_db_views::{ comment_view::CommentView, community::community_view::CommunityView, moderator::{ @@ -16,7 +17,6 @@ use lemmy_db::views::{ site_view::SiteView, user_view::UserViewSafe, }; -use lemmy_db_schema::source::{category::*, user::User_}; use serde::{Deserialize, Serialize}; #[derive(Deserialize)] diff --git a/lemmy_structs/src/user.rs b/lemmy_structs/src/user.rs index 52871696c..4b4d6a886 100644 --- a/lemmy_structs/src/user.rs +++ b/lemmy_structs/src/user.rs @@ -1,4 +1,4 @@ -use lemmy_db::views::{ +use lemmy_db_views::{ comment_view::CommentView, community::{ community_follower_view::CommunityFollowerView, diff --git a/lemmy_utils/src/settings.rs b/lemmy_utils/src/settings.rs index 4edcbd13b..4ca87f282 100644 --- a/lemmy_utils/src/settings.rs +++ b/lemmy_utils/src/settings.rs @@ -89,7 +89,7 @@ impl Settings { /// added to the config. /// /// Note: The env var `LEMMY_DATABASE_URL` is parsed in - /// `lemmy_db/src/lib.rs::get_database_url_from_env()` + /// `lemmy_db_queries/src/lib.rs::get_database_url_from_env()` fn init() -> Result { let mut s = Config::new(); diff --git a/lemmy_websocket/Cargo.toml b/lemmy_websocket/Cargo.toml index 90cf0e175..4f036ae52 100644 --- a/lemmy_websocket/Cargo.toml +++ b/lemmy_websocket/Cargo.toml @@ -11,7 +11,7 @@ path = "src/lib.rs" [dependencies] lemmy_utils = { path = "../lemmy_utils" } lemmy_structs = { path = "../lemmy_structs" } -lemmy_db = { path = "../lemmy_db" } +lemmy_db_queries = { path = "../lemmy_db_queries" } lemmy_db_schema = { path = "../lemmy_db_schema" } lemmy_rate_limit = { path = "../lemmy_rate_limit" } reqwest = { version = "0.10.10", features = ["json"] } diff --git a/src/routes/feeds.rs b/src/routes/feeds.rs index fc397fff0..d7862dcd5 100644 --- a/src/routes/feeds.rs +++ b/src/routes/feeds.rs @@ -5,16 +5,16 @@ use diesel::PgConnection; use lemmy_api::claims::Claims; use lemmy_db::{ source::{community::Community_, user::User}, - views::{ - comment_view::{CommentQueryBuilder, CommentView}, - post_view::{PostQueryBuilder, PostView}, - site_view::SiteView, - user_mention_view::{UserMentionQueryBuilder, UserMentionView}, - }, ListingType, SortType, }; use lemmy_db_schema::source::{community::Community, user::User_}; +use lemmy_db_views::{ + comment_view::{CommentQueryBuilder, CommentView}, + post_view::{PostQueryBuilder, PostView}, + site_view::SiteView, + user_mention_view::{UserMentionQueryBuilder, UserMentionView}, +}; use lemmy_structs::blocking; use lemmy_utils::{settings::Settings, utils::markdown_to_html, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/src/routes/nodeinfo.rs b/src/routes/nodeinfo.rs index 9f63a523b..e6c5e6c42 100644 --- a/src/routes/nodeinfo.rs +++ b/src/routes/nodeinfo.rs @@ -1,7 +1,7 @@ use actix_web::{body::Body, error::ErrorBadRequest, *}; use anyhow::anyhow; use lemmy_api::version; -use lemmy_db::views::site_view::SiteView; +use lemmy_db_views::site_view::SiteView; use lemmy_structs::blocking; use lemmy_utils::{settings::Settings, LemmyError}; use lemmy_websocket::LemmyContext; From 95e30f0e08eb86d388a9d739844626d5c82a5078 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 22 Dec 2020 00:27:42 +0100 Subject: [PATCH 2/3] Split up lemmy_db_views, put lemmy_rate_limit into lemmy_utils --- Cargo.lock | 50 ++++++++++--------- Cargo.toml | 8 +-- lemmy_api/Cargo.toml | 3 +- lemmy_api/src/comment.rs | 2 +- lemmy_api/src/community.rs | 14 +++--- lemmy_api/src/lib.rs | 4 +- lemmy_api/src/post.rs | 12 ++++- lemmy_api/src/site.rs | 28 ++++++----- lemmy_api/src/user.rs | 10 ++-- lemmy_apub/Cargo.toml | 1 + lemmy_apub/src/activities/receive/comment.rs | 2 +- .../src/activities/receive/comment_undo.rs | 2 +- .../src/activities/receive/community.rs | 4 +- lemmy_apub/src/activities/receive/post.rs | 2 +- .../src/activities/receive/post_undo.rs | 2 +- .../src/activities/receive/private_message.rs | 2 +- lemmy_apub/src/activities/send/comment.rs | 2 +- lemmy_apub/src/activities/send/community.rs | 4 +- lemmy_apub/src/activities/send/post.rs | 2 +- .../src/activities/send/private_message.rs | 2 +- lemmy_apub/src/activities/send/user.rs | 2 +- lemmy_apub/src/activity_queue.rs | 2 +- lemmy_apub/src/extensions/group_extensions.rs | 2 +- lemmy_apub/src/fetcher.rs | 10 ++-- lemmy_apub/src/http/comment.rs | 2 +- lemmy_apub/src/http/community.rs | 4 +- lemmy_apub/src/http/mod.rs | 2 +- lemmy_apub/src/http/post.rs | 2 +- lemmy_apub/src/http/user.rs | 2 +- lemmy_apub/src/inbox/community_inbox.rs | 4 +- lemmy_apub/src/inbox/mod.rs | 2 +- lemmy_apub/src/inbox/receive_for_community.rs | 2 +- lemmy_apub/src/inbox/shared_inbox.rs | 2 +- lemmy_apub/src/inbox/user_inbox.rs | 2 +- lemmy_apub/src/lib.rs | 2 +- lemmy_apub/src/objects/comment.rs | 2 +- lemmy_apub/src/objects/community.rs | 4 +- lemmy_apub/src/objects/mod.rs | 2 +- lemmy_apub/src/objects/post.rs | 2 +- lemmy_apub/src/objects/private_message.rs | 2 +- lemmy_apub/src/objects/user.rs | 2 +- lemmy_db_queries/Cargo.toml | 2 +- .../src/aggregates}/comment_aggregates.rs | 10 +++- .../src/aggregates}/community_aggregates.rs | 10 +++- .../src/aggregates/mod.rs | 0 .../src/aggregates}/post_aggregates.rs | 10 +++- .../src/aggregates}/site_aggregates.rs | 9 +++- .../src/aggregates}/user_aggregates.rs | 10 +++- lemmy_db_queries/src/lib.rs | 8 +++ lemmy_db_schema/src/source/comment_report.rs | 4 +- lemmy_db_schema/src/source/post_report.rs | 4 +- lemmy_db_views/Cargo.toml | 1 - lemmy_db_views/src/comment_report_view.rs | 3 +- lemmy_db_views/src/comment_view.rs | 16 ++++-- lemmy_db_views/src/lib.rs | 11 ---- lemmy_db_views/src/post_report_view.rs | 3 +- lemmy_db_views/src/post_view.rs | 16 ++++-- lemmy_db_views/src/private_message_view.rs | 3 +- lemmy_db_views/src/site_view.rs | 3 +- .../Cargo.toml | 5 +- .../src}/community_follower_view.rs | 3 +- .../src}/community_moderator_view.rs | 3 +- .../src}/community_user_ban_view.rs | 2 +- .../src}/community_view.rs | 11 ++-- .../mod.rs => lemmy_db_views_actor/src/lib.rs | 2 + .../src/user_mention_view.rs | 12 +++-- .../src/user_view.rs | 12 +++-- lemmy_db_views_moderator/Cargo.toml | 10 ++++ .../src/lib.rs | 0 .../src}/mod_add_community_view.rs | 3 +- .../src}/mod_add_view.rs | 3 +- .../src}/mod_ban_from_community_view.rs | 3 +- .../src}/mod_ban_view.rs | 3 +- .../src}/mod_lock_post_view.rs | 3 +- .../src}/mod_remove_comment_view.rs | 3 +- .../src}/mod_remove_community_view.rs | 3 +- .../src}/mod_remove_post_view.rs | 3 +- .../src}/mod_sticky_post_view.rs | 3 +- lemmy_rate_limit/Cargo.toml | 18 ------- lemmy_structs/Cargo.toml | 2 + lemmy_structs/src/community.rs | 10 ++-- lemmy_structs/src/lib.rs | 2 +- lemmy_structs/src/post.rs | 2 +- lemmy_structs/src/site.rs | 29 +++++------ lemmy_structs/src/user.rs | 8 +-- lemmy_utils/Cargo.toml | 4 ++ lemmy_utils/src/lib.rs | 3 ++ .../src/rate_limit/mod.rs | 9 ++-- .../src/rate_limit}/rate_limiter.rs | 2 +- lemmy_websocket/Cargo.toml | 1 - lemmy_websocket/src/chat_server.rs | 2 +- lemmy_websocket/src/lib.rs | 2 +- src/code_migrations.rs | 2 +- src/main.rs | 9 ++-- src/routes/api.rs | 2 +- src/routes/feeds.rs | 4 +- src/routes/images.rs | 3 +- src/routes/webfinger.rs | 2 +- tests/integration_test.rs | 9 ++-- 99 files changed, 294 insertions(+), 253 deletions(-) rename {lemmy_db_aggregates/src => lemmy_db_queries/src/aggregates}/comment_aggregates.rs (97%) rename {lemmy_db_aggregates/src => lemmy_db_queries/src/aggregates}/community_aggregates.rs (97%) rename lemmy_db_aggregates/src/lib.rs => lemmy_db_queries/src/aggregates/mod.rs (100%) rename {lemmy_db_aggregates/src => lemmy_db_queries/src/aggregates}/post_aggregates.rs (97%) rename {lemmy_db_aggregates/src => lemmy_db_queries/src/aggregates}/site_aggregates.rs (97%) rename {lemmy_db_aggregates/src => lemmy_db_queries/src/aggregates}/user_aggregates.rs (97%) rename {lemmy_db_aggregates => lemmy_db_views_actor}/Cargo.toml (78%) rename {lemmy_db_views/src/community => lemmy_db_views_actor/src}/community_follower_view.rs (97%) rename {lemmy_db_views/src/community => lemmy_db_views_actor/src}/community_moderator_view.rs (97%) rename {lemmy_db_views/src/community => lemmy_db_views_actor/src}/community_user_ban_view.rs (97%) rename {lemmy_db_views/src/community => lemmy_db_views_actor/src}/community_view.rs (97%) rename lemmy_db_views/src/community/mod.rs => lemmy_db_views_actor/src/lib.rs (72%) rename {lemmy_db_views => lemmy_db_views_actor}/src/user_mention_view.rs (98%) rename {lemmy_db_views => lemmy_db_views_actor}/src/user_view.rs (96%) create mode 100644 lemmy_db_views_moderator/Cargo.toml rename lemmy_db_views/src/moderator/mod.rs => lemmy_db_views_moderator/src/lib.rs (100%) rename {lemmy_db_views/src/moderator => lemmy_db_views_moderator/src}/mod_add_community_view.rs (97%) rename {lemmy_db_views/src/moderator => lemmy_db_views_moderator/src}/mod_add_view.rs (96%) rename {lemmy_db_views/src/moderator => lemmy_db_views_moderator/src}/mod_ban_from_community_view.rs (97%) rename {lemmy_db_views/src/moderator => lemmy_db_views_moderator/src}/mod_ban_view.rs (96%) rename {lemmy_db_views/src/moderator => lemmy_db_views_moderator/src}/mod_lock_post_view.rs (96%) rename {lemmy_db_views/src/moderator => lemmy_db_views_moderator/src}/mod_remove_comment_view.rs (97%) rename {lemmy_db_views/src/moderator => lemmy_db_views_moderator/src}/mod_remove_community_view.rs (96%) rename {lemmy_db_views/src/moderator => lemmy_db_views_moderator/src}/mod_remove_post_view.rs (96%) rename {lemmy_db_views/src/moderator => lemmy_db_views_moderator/src}/mod_sticky_post_view.rs (96%) delete mode 100644 lemmy_rate_limit/Cargo.toml rename lemmy_rate_limit/src/lib.rs => lemmy_utils/src/rate_limit/mod.rs (98%) rename {lemmy_rate_limit/src => lemmy_utils/src/rate_limit}/rate_limiter.rs (98%) diff --git a/Cargo.lock b/Cargo.lock index dd16aa97f..782458b1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1720,7 +1720,8 @@ dependencies = [ "lemmy_db_queries", "lemmy_db_schema", "lemmy_db_views", - "lemmy_rate_limit", + "lemmy_db_views_actor", + "lemmy_db_views_moderator", "lemmy_structs", "lemmy_utils", "lemmy_websocket", @@ -1766,6 +1767,7 @@ dependencies = [ "lemmy_db_queries", "lemmy_db_schema", "lemmy_db_views", + "lemmy_db_views_actor", "lemmy_structs", "lemmy_utils", "lemmy_websocket", @@ -1785,17 +1787,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "lemmy_db_aggregates" -version = "0.1.0" -dependencies = [ - "chrono", - "diesel", - "lemmy_db_queries", - "lemmy_db_schema", - "serde 1.0.118", -] - [[package]] name = "lemmy_db_queries" version = "0.1.0" @@ -1834,23 +1825,29 @@ name = "lemmy_db_views" version = "0.1.0" dependencies = [ "diesel", - "lemmy_db_aggregates", "lemmy_db_queries", "lemmy_db_schema", "serde 1.0.118", ] [[package]] -name = "lemmy_rate_limit" +name = "lemmy_db_views_actor" version = "0.1.0" dependencies = [ - "actix-web", - "futures", - "lemmy_utils", - "log", - "strum", - "strum_macros", - "tokio 0.3.6", + "diesel", + "lemmy_db_queries", + "lemmy_db_schema", + "serde 1.0.118", +] + +[[package]] +name = "lemmy_db_views_moderator" +version = "0.1.0" +dependencies = [ + "diesel", + "lemmy_db_queries", + "lemmy_db_schema", + "serde 1.0.118", ] [[package]] @@ -1874,11 +1871,11 @@ dependencies = [ "lazy_static", "lemmy_api", "lemmy_apub", - "lemmy_db_aggregates", "lemmy_db_queries", "lemmy_db_schema", "lemmy_db_views", - "lemmy_rate_limit", + "lemmy_db_views_actor", + "lemmy_db_views_moderator", "lemmy_structs", "lemmy_utils", "lemmy_websocket", @@ -1904,6 +1901,8 @@ dependencies = [ "lemmy_db_queries", "lemmy_db_schema", "lemmy_db_views", + "lemmy_db_views_actor", + "lemmy_db_views_moderator", "lemmy_utils", "log", "serde 1.0.118", @@ -1920,6 +1919,7 @@ dependencies = [ "chrono", "comrak", "config", + "futures", "itertools", "lazy_static", "lettre", @@ -1931,7 +1931,10 @@ dependencies = [ "reqwest", "serde 1.0.118", "serde_json", + "strum", + "strum_macros", "thiserror", + "tokio 0.3.6", "url", ] @@ -1946,7 +1949,6 @@ dependencies = [ "diesel", "lemmy_db_queries", "lemmy_db_schema", - "lemmy_rate_limit", "lemmy_structs", "lemmy_utils", "log", diff --git a/Cargo.toml b/Cargo.toml index f6234416b..ca2d291c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,10 @@ members = [ "lemmy_utils", "lemmy_db_queries", "lemmy_db_schema", + "lemmy_db_views", + "lemmy_db_views_actor", + "lemmy_db_views_actor", "lemmy_structs", - "lemmy_rate_limit", "lemmy_websocket", ] @@ -25,9 +27,9 @@ lemmy_utils = { path = "./lemmy_utils" } lemmy_db_schema = { path = "./lemmy_db_schema" } lemmy_db_queries = { path = "lemmy_db_queries" } lemmy_db_views = { path = "./lemmy_db_views" } -lemmy_db_aggregates = { path = "./lemmy_db_aggregates" } +lemmy_db_views_moderator = { path = "./lemmy_db_views_moderator" } +lemmy_db_views_actor = { path = "lemmy_db_views_actor" } lemmy_structs = { path = "./lemmy_structs" } -lemmy_rate_limit = { path = "./lemmy_rate_limit" } lemmy_websocket = { path = "./lemmy_websocket" } diesel = "1.4.5" diesel_migrations = "1.4.0" diff --git a/lemmy_api/Cargo.toml b/lemmy_api/Cargo.toml index b9bda5990..e0766df3a 100644 --- a/lemmy_api/Cargo.toml +++ b/lemmy_api/Cargo.toml @@ -14,8 +14,9 @@ lemmy_utils = { path = "../lemmy_utils" } lemmy_db_queries = { path = "../lemmy_db_queries" } lemmy_db_schema = { path = "../lemmy_db_schema" } lemmy_db_views = { path = "../lemmy_db_views" } +lemmy_db_views_moderator = { path = "../lemmy_db_views_moderator" } +lemmy_db_views_actor = { path = "../lemmy_db_views_actor" } lemmy_structs = { path = "../lemmy_structs" } -lemmy_rate_limit = { path = "../lemmy_rate_limit" } lemmy_websocket = { path = "../lemmy_websocket" } diesel = "1.4.5" bcrypt = "0.9.0" diff --git a/lemmy_api/src/comment.rs b/lemmy_api/src/comment.rs index eb8d68b7c..840600cbc 100644 --- a/lemmy_api/src/comment.rs +++ b/lemmy_api/src/comment.rs @@ -10,7 +10,7 @@ use crate::{ }; use actix_web::web::Data; use lemmy_apub::{ApubLikeableType, ApubObjectType}; -use lemmy_db::{ +use lemmy_db_queries::{ source::comment::Comment_, Crud, Likeable, diff --git a/lemmy_api/src/community.rs b/lemmy_api/src/community.rs index 8c2d9ad5a..f01e07404 100644 --- a/lemmy_api/src/community.rs +++ b/lemmy_api/src/community.rs @@ -9,7 +9,7 @@ use crate::{ use actix_web::web::Data; use anyhow::Context; use lemmy_apub::ActorType; -use lemmy_db::{ +use lemmy_db_queries::{ diesel_option_overwrite, source::{ comment::Comment_, @@ -27,13 +27,11 @@ use lemmy_db_schema::{ naive_now, source::{comment::Comment, community::*, moderator::*, post::Post, site::*}, }; -use lemmy_db_views::{ - comment_view::CommentQueryBuilder, - community::{ - community_follower_view::CommunityFollowerView, - community_moderator_view::CommunityModeratorView, - community_view::{CommunityQueryBuilder, CommunityView}, - }, +use lemmy_db_views::comment_view::CommentQueryBuilder; +use lemmy_db_views_actor::{ + community_follower_view::CommunityFollowerView, + community_moderator_view::CommunityModeratorView, + community_view::{CommunityQueryBuilder, CommunityView}, user_view::UserViewSafe, }; use lemmy_structs::{blocking, community::*}; diff --git a/lemmy_api/src/lib.rs b/lemmy_api/src/lib.rs index 72c2316de..c1dee7aa3 100644 --- a/lemmy_api/src/lib.rs +++ b/lemmy_api/src/lib.rs @@ -1,6 +1,6 @@ use crate::claims::Claims; use actix_web::{web, web::Data}; -use lemmy_db::{ +use lemmy_db_queries::{ source::{ community::{CommunityModerator_, Community_}, site::Site_, @@ -14,7 +14,7 @@ use lemmy_db_schema::source::{ site::Site, user::User_, }; -use lemmy_db_views::community::{ +use lemmy_db_views_actor::{ community_user_ban_view::CommunityUserBanView, community_view::CommunityView, }; diff --git a/lemmy_api/src/post.rs b/lemmy_api/src/post.rs index 6f5149702..07a39732d 100644 --- a/lemmy_api/src/post.rs +++ b/lemmy_api/src/post.rs @@ -10,7 +10,15 @@ use crate::{ }; use actix_web::web::Data; use lemmy_apub::{ApubLikeableType, ApubObjectType}; -use lemmy_db::{source::post::Post_, Crud, Likeable, ListingType, Reportable, Saveable, SortType}; +use lemmy_db_queries::{ + source::post::Post_, + Crud, + Likeable, + ListingType, + Reportable, + Saveable, + SortType, +}; use lemmy_db_schema::{ naive_now, source::{ @@ -21,10 +29,10 @@ use lemmy_db_schema::{ }; use lemmy_db_views::{ comment_view::CommentQueryBuilder, - community::community_moderator_view::CommunityModeratorView, post_report_view::{PostReportQueryBuilder, PostReportView}, post_view::{PostQueryBuilder, PostView}, }; +use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView; use lemmy_structs::{blocking, post::*}; use lemmy_utils::{ apub::{make_apub_endpoint, EndpointType}, diff --git a/lemmy_api/src/site.rs b/lemmy_api/src/site.rs index dcf35c007..2f5f4a3a9 100644 --- a/lemmy_api/src/site.rs +++ b/lemmy_api/src/site.rs @@ -9,7 +9,7 @@ use crate::{ use actix_web::web::Data; use anyhow::Context; use lemmy_apub::fetcher::search_by_apub_id; -use lemmy_db::{ +use lemmy_db_queries::{ diesel_option_overwrite, source::{category::Category_, site::Site_}, Crud, @@ -26,22 +26,24 @@ use lemmy_db_schema::{ }; use lemmy_db_views::{ comment_view::CommentQueryBuilder, - community::community_view::CommunityQueryBuilder, - moderator::{ - mod_add_community_view::ModAddCommunityView, - mod_add_view::ModAddView, - mod_ban_from_community_view::ModBanFromCommunityView, - mod_ban_view::ModBanView, - mod_lock_post_view::ModLockPostView, - mod_remove_comment_view::ModRemoveCommentView, - mod_remove_community_view::ModRemoveCommunityView, - mod_remove_post_view::ModRemovePostView, - mod_sticky_post_view::ModStickyPostView, - }, post_view::PostQueryBuilder, site_view::SiteView, +}; +use lemmy_db_views_actor::{ + community_view::CommunityQueryBuilder, user_view::{UserQueryBuilder, UserViewSafe}, }; +use lemmy_db_views_moderator::{ + mod_add_community_view::ModAddCommunityView, + mod_add_view::ModAddView, + mod_ban_from_community_view::ModBanFromCommunityView, + mod_ban_view::ModBanView, + mod_lock_post_view::ModLockPostView, + mod_remove_comment_view::ModRemoveCommentView, + mod_remove_community_view::ModRemoveCommunityView, + mod_remove_post_view::ModRemovePostView, + mod_sticky_post_view::ModStickyPostView, +}; use lemmy_structs::{blocking, site::*, user::Register}; use lemmy_utils::{ location_info, diff --git a/lemmy_api/src/user.rs b/lemmy_api/src/user.rs index 908911546..91c3b11ad 100644 --- a/lemmy_api/src/user.rs +++ b/lemmy_api/src/user.rs @@ -14,7 +14,7 @@ use bcrypt::verify; use captcha::{gen, Difficulty}; use chrono::Duration; use lemmy_apub::ApubObjectType; -use lemmy_db::{ +use lemmy_db_queries::{ diesel_option_overwrite, source::{ comment::Comment_, @@ -49,13 +49,13 @@ use lemmy_db_schema::{ use lemmy_db_views::{ comment_report_view::CommentReportView, comment_view::CommentQueryBuilder, - community::{ - community_follower_view::CommunityFollowerView, - community_moderator_view::CommunityModeratorView, - }, post_report_view::PostReportView, post_view::PostQueryBuilder, private_message_view::{PrivateMessageQueryBuilder, PrivateMessageView}, +}; +use lemmy_db_views_actor::{ + community_follower_view::CommunityFollowerView, + community_moderator_view::CommunityModeratorView, user_mention_view::{UserMentionQueryBuilder, UserMentionView}, user_view::{UserViewDangerous, UserViewSafe}, }; diff --git a/lemmy_apub/Cargo.toml b/lemmy_apub/Cargo.toml index a912f4487..a524daf14 100644 --- a/lemmy_apub/Cargo.toml +++ b/lemmy_apub/Cargo.toml @@ -13,6 +13,7 @@ lemmy_utils = { path = "../lemmy_utils" } lemmy_db_queries = { path = "../lemmy_db_queries" } lemmy_db_schema = { path = "../lemmy_db_schema" } lemmy_db_views = { path = "../lemmy_db_views" } +lemmy_db_views_actor = { path = "../lemmy_db_views_actor" } lemmy_structs = { path = "../lemmy_structs" } lemmy_websocket = { path = "../lemmy_websocket" } diesel = "1.4.5" diff --git a/lemmy_apub/src/activities/receive/comment.rs b/lemmy_apub/src/activities/receive/comment.rs index 483ef54fe..7ba3a05ca 100644 --- a/lemmy_apub/src/activities/receive/comment.rs +++ b/lemmy_apub/src/activities/receive/comment.rs @@ -4,7 +4,7 @@ use activitystreams::{ base::ExtendsExt, }; use anyhow::Context; -use lemmy_db::{source::comment::Comment_, Crud, Likeable}; +use lemmy_db_queries::{source::comment::Comment_, Crud, Likeable}; use lemmy_db_schema::source::{ comment::{Comment, CommentLike, CommentLikeForm}, post::Post, diff --git a/lemmy_apub/src/activities/receive/comment_undo.rs b/lemmy_apub/src/activities/receive/comment_undo.rs index 4f845523d..5dc021ad3 100644 --- a/lemmy_apub/src/activities/receive/comment_undo.rs +++ b/lemmy_apub/src/activities/receive/comment_undo.rs @@ -1,6 +1,6 @@ use crate::activities::receive::get_actor_as_user; use activitystreams::activity::{Dislike, Like}; -use lemmy_db::{source::comment::Comment_, Likeable}; +use lemmy_db_queries::{source::comment::Comment_, Likeable}; use lemmy_db_schema::source::comment::{Comment, CommentLike}; use lemmy_db_views::comment_view::CommentView; use lemmy_structs::{blocking, comment::CommentResponse}; diff --git a/lemmy_apub/src/activities/receive/community.rs b/lemmy_apub/src/activities/receive/community.rs index f493a5632..7f5523773 100644 --- a/lemmy_apub/src/activities/receive/community.rs +++ b/lemmy_apub/src/activities/receive/community.rs @@ -4,9 +4,9 @@ use activitystreams::{ base::{AnyBase, ExtendsExt}, }; use anyhow::Context; -use lemmy_db::{source::community::Community_, ApubObject}; +use lemmy_db_queries::{source::community::Community_, ApubObject}; use lemmy_db_schema::source::community::Community; -use lemmy_db_views::community::community_view::CommunityView; +use lemmy_db_views_actor::community_view::CommunityView; use lemmy_structs::{blocking, community::CommunityResponse}; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation}; diff --git a/lemmy_apub/src/activities/receive/post.rs b/lemmy_apub/src/activities/receive/post.rs index 2b46cf54a..c35a02818 100644 --- a/lemmy_apub/src/activities/receive/post.rs +++ b/lemmy_apub/src/activities/receive/post.rs @@ -4,7 +4,7 @@ use activitystreams::{ prelude::*, }; use anyhow::Context; -use lemmy_db::{source::post::Post_, Likeable}; +use lemmy_db_queries::{source::post::Post_, Likeable}; use lemmy_db_schema::source::post::{Post, PostLike, PostLikeForm}; use lemmy_db_views::post_view::PostView; use lemmy_structs::{blocking, post::PostResponse}; diff --git a/lemmy_apub/src/activities/receive/post_undo.rs b/lemmy_apub/src/activities/receive/post_undo.rs index bf188a9f6..0b9d6f4a4 100644 --- a/lemmy_apub/src/activities/receive/post_undo.rs +++ b/lemmy_apub/src/activities/receive/post_undo.rs @@ -1,6 +1,6 @@ use crate::activities::receive::get_actor_as_user; use activitystreams::activity::{Dislike, Like}; -use lemmy_db::{source::post::Post_, Likeable}; +use lemmy_db_queries::{source::post::Post_, Likeable}; use lemmy_db_schema::source::post::{Post, PostLike}; use lemmy_db_views::post_view::PostView; use lemmy_structs::{blocking, post::PostResponse}; diff --git a/lemmy_apub/src/activities/receive/private_message.rs b/lemmy_apub/src/activities/receive/private_message.rs index d2755094a..bd21f4c7f 100644 --- a/lemmy_apub/src/activities/receive/private_message.rs +++ b/lemmy_apub/src/activities/receive/private_message.rs @@ -13,7 +13,7 @@ use activitystreams::{ public, }; use anyhow::{anyhow, Context}; -use lemmy_db::source::private_message::PrivateMessage_; +use lemmy_db_queries::source::private_message::PrivateMessage_; use lemmy_db_schema::source::private_message::PrivateMessage; use lemmy_db_views::private_message_view::PrivateMessageView; use lemmy_structs::{blocking, user::PrivateMessageResponse}; diff --git a/lemmy_apub/src/activities/send/comment.rs b/lemmy_apub/src/activities/send/comment.rs index 4ddd2d321..3f7a59de3 100644 --- a/lemmy_apub/src/activities/send/comment.rs +++ b/lemmy_apub/src/activities/send/comment.rs @@ -26,7 +26,7 @@ use activitystreams::{ }; use anyhow::anyhow; use itertools::Itertools; -use lemmy_db::{Crud, DbPool}; +use lemmy_db_queries::{Crud, DbPool}; use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post, user::User_}; use lemmy_structs::{blocking, WebFingerResponse}; use lemmy_utils::{ diff --git a/lemmy_apub/src/activities/send/community.rs b/lemmy_apub/src/activities/send/community.rs index 1a4a4a572..e148b4e94 100644 --- a/lemmy_apub/src/activities/send/community.rs +++ b/lemmy_apub/src/activities/send/community.rs @@ -23,9 +23,9 @@ use activitystreams::{ }; use anyhow::Context; use itertools::Itertools; -use lemmy_db::DbPool; +use lemmy_db_queries::DbPool; use lemmy_db_schema::source::community::Community; -use lemmy_db_views::community::community_follower_view::CommunityFollowerView; +use lemmy_db_views_actor::community_follower_view::CommunityFollowerView; use lemmy_structs::blocking; use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/activities/send/post.rs b/lemmy_apub/src/activities/send/post.rs index 732a53c33..4af40de28 100644 --- a/lemmy_apub/src/activities/send/post.rs +++ b/lemmy_apub/src/activities/send/post.rs @@ -21,7 +21,7 @@ use activitystreams::{ prelude::*, public, }; -use lemmy_db::Crud; +use lemmy_db_queries::Crud; use lemmy_db_schema::source::{community::Community, post::Post, user::User_}; use lemmy_structs::blocking; use lemmy_utils::LemmyError; diff --git a/lemmy_apub/src/activities/send/private_message.rs b/lemmy_apub/src/activities/send/private_message.rs index bcbb303bc..d920f3dec 100644 --- a/lemmy_apub/src/activities/send/private_message.rs +++ b/lemmy_apub/src/activities/send/private_message.rs @@ -16,7 +16,7 @@ use activitystreams::{ }, prelude::*, }; -use lemmy_db::Crud; +use lemmy_db_queries::Crud; use lemmy_db_schema::source::{private_message::PrivateMessage, user::User_}; use lemmy_structs::blocking; use lemmy_utils::LemmyError; diff --git a/lemmy_apub/src/activities/send/user.rs b/lemmy_apub/src/activities/send/user.rs index cad20e9d9..049496f73 100644 --- a/lemmy_apub/src/activities/send/user.rs +++ b/lemmy_apub/src/activities/send/user.rs @@ -13,7 +13,7 @@ use activitystreams::{ base::{AnyBase, BaseExt, ExtendsExt}, object::ObjectExt, }; -use lemmy_db::{ApubObject, DbPool, Followable}; +use lemmy_db_queries::{ApubObject, DbPool, Followable}; use lemmy_db_schema::source::{ community::{Community, CommunityFollower, CommunityFollowerForm}, user::User_, diff --git a/lemmy_apub/src/activity_queue.rs b/lemmy_apub/src/activity_queue.rs index fe70d8e8b..0dd7776fb 100644 --- a/lemmy_apub/src/activity_queue.rs +++ b/lemmy_apub/src/activity_queue.rs @@ -19,7 +19,7 @@ use background_jobs::{ WorkerConfig, }; use itertools::Itertools; -use lemmy_db::DbPool; +use lemmy_db_queries::DbPool; use lemmy_db_schema::source::{community::Community, user::User_}; use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/extensions/group_extensions.rs b/lemmy_apub/src/extensions/group_extensions.rs index 2d8cfe799..b9790b231 100644 --- a/lemmy_apub/src/extensions/group_extensions.rs +++ b/lemmy_apub/src/extensions/group_extensions.rs @@ -1,7 +1,7 @@ use activitystreams::unparsed::UnparsedMutExt; use activitystreams_ext::UnparsedExtension; use diesel::PgConnection; -use lemmy_db::Crud; +use lemmy_db_queries::Crud; use lemmy_db_schema::source::category::Category; use lemmy_utils::LemmyError; use serde::{Deserialize, Serialize}; diff --git a/lemmy_apub/src/fetcher.rs b/lemmy_apub/src/fetcher.rs index e67fbc969..4e1fa98a6 100644 --- a/lemmy_apub/src/fetcher.rs +++ b/lemmy_apub/src/fetcher.rs @@ -12,7 +12,7 @@ use activitystreams::{base::BaseExt, collection::OrderedCollection, prelude::*}; use anyhow::{anyhow, Context}; use chrono::NaiveDateTime; use diesel::result::Error::NotFound; -use lemmy_db::{source::user::User, ApubObject, Crud, Joinable, SearchType}; +use lemmy_db_queries::{source::user::User, ApubObject, Crud, Joinable, SearchType}; use lemmy_db_schema::{ naive_now, source::{ @@ -22,12 +22,8 @@ use lemmy_db_schema::{ user::User_, }, }; -use lemmy_db_views::{ - comment_view::CommentView, - community::community_view::CommunityView, - post_view::PostView, - user_view::UserViewSafe, -}; +use lemmy_db_views::{comment_view::CommentView, post_view::PostView}; +use lemmy_db_views_actor::{community_view::CommunityView, user_view::UserViewSafe}; use lemmy_structs::{blocking, site::SearchResponse}; use lemmy_utils::{ location_info, diff --git a/lemmy_apub/src/http/comment.rs b/lemmy_apub/src/http/comment.rs index f71d542b0..44397db60 100644 --- a/lemmy_apub/src/http/comment.rs +++ b/lemmy_apub/src/http/comment.rs @@ -4,7 +4,7 @@ use crate::{ }; use actix_web::{body::Body, web, web::Path, HttpResponse}; use diesel::result::Error::NotFound; -use lemmy_db::Crud; +use lemmy_db_queries::Crud; use lemmy_db_schema::source::comment::Comment; use lemmy_structs::blocking; use lemmy_utils::LemmyError; diff --git a/lemmy_apub/src/http/community.rs b/lemmy_apub/src/http/community.rs index 011f2d889..668c90a3a 100644 --- a/lemmy_apub/src/http/community.rs +++ b/lemmy_apub/src/http/community.rs @@ -9,9 +9,9 @@ use activitystreams::{ collection::{CollectionExt, OrderedCollection, UnorderedCollection}, }; use actix_web::{body::Body, web, HttpResponse}; -use lemmy_db::source::{community::Community_, post::Post_}; +use lemmy_db_queries::source::{community::Community_, post::Post_}; use lemmy_db_schema::source::{community::Community, post::Post}; -use lemmy_db_views::community::community_follower_view::CommunityFollowerView; +use lemmy_db_views_actor::community_follower_view::CommunityFollowerView; use lemmy_structs::blocking; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/http/mod.rs b/lemmy_apub/src/http/mod.rs index 5d45a725f..0d77aed77 100644 --- a/lemmy_apub/src/http/mod.rs +++ b/lemmy_apub/src/http/mod.rs @@ -1,6 +1,6 @@ use crate::APUB_JSON_CONTENT_TYPE; use actix_web::{body::Body, web, HttpResponse}; -use lemmy_db::source::activity::Activity_; +use lemmy_db_queries::source::activity::Activity_; use lemmy_db_schema::source::activity::Activity; use lemmy_structs::blocking; use lemmy_utils::{settings::Settings, LemmyError}; diff --git a/lemmy_apub/src/http/post.rs b/lemmy_apub/src/http/post.rs index 8ade35296..66adae3ac 100644 --- a/lemmy_apub/src/http/post.rs +++ b/lemmy_apub/src/http/post.rs @@ -4,7 +4,7 @@ use crate::{ }; use actix_web::{body::Body, web, HttpResponse}; use diesel::result::Error::NotFound; -use lemmy_db::Crud; +use lemmy_db_queries::Crud; use lemmy_db_schema::source::post::Post; use lemmy_structs::blocking; use lemmy_utils::LemmyError; diff --git a/lemmy_apub/src/http/user.rs b/lemmy_apub/src/http/user.rs index b01347e0d..d3b1b4d4b 100644 --- a/lemmy_apub/src/http/user.rs +++ b/lemmy_apub/src/http/user.rs @@ -9,7 +9,7 @@ use activitystreams::{ collection::{CollectionExt, OrderedCollection}, }; use actix_web::{body::Body, web, HttpResponse}; -use lemmy_db::source::user::User; +use lemmy_db_queries::source::user::User; use lemmy_db_schema::source::user::User_; use lemmy_structs::blocking; use lemmy_utils::LemmyError; diff --git a/lemmy_apub/src/inbox/community_inbox.rs b/lemmy_apub/src/inbox/community_inbox.rs index e6d7b29c7..1e44254c2 100644 --- a/lemmy_apub/src/inbox/community_inbox.rs +++ b/lemmy_apub/src/inbox/community_inbox.rs @@ -26,12 +26,12 @@ use activitystreams::{ }; use actix_web::{web, HttpRequest, HttpResponse}; use anyhow::{anyhow, Context}; -use lemmy_db::{source::community::Community_, ApubObject, DbPool, Followable}; +use lemmy_db_queries::{source::community::Community_, ApubObject, DbPool, Followable}; use lemmy_db_schema::source::{ community::{Community, CommunityFollower, CommunityFollowerForm}, user::User_, }; -use lemmy_db_views::community::community_user_ban_view::CommunityUserBanView; +use lemmy_db_views_actor::community_user_ban_view::CommunityUserBanView; use lemmy_structs::blocking; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/inbox/mod.rs b/lemmy_apub/src/inbox/mod.rs index 9b2009342..a91dd48eb 100644 --- a/lemmy_apub/src/inbox/mod.rs +++ b/lemmy_apub/src/inbox/mod.rs @@ -12,7 +12,7 @@ use activitystreams::{ }; use actix_web::HttpRequest; use anyhow::{anyhow, Context}; -use lemmy_db::{source::activity::Activity_, ApubObject, DbPool}; +use lemmy_db_queries::{source::activity::Activity_, ApubObject, DbPool}; use lemmy_db_schema::source::{activity::Activity, community::Community, user::User_}; use lemmy_structs::blocking; use lemmy_utils::{location_info, settings::Settings, LemmyError}; diff --git a/lemmy_apub/src/inbox/receive_for_community.rs b/lemmy_apub/src/inbox/receive_for_community.rs index 31c5efba1..934404242 100644 --- a/lemmy_apub/src/inbox/receive_for_community.rs +++ b/lemmy_apub/src/inbox/receive_for_community.rs @@ -41,7 +41,7 @@ use activitystreams::{ }; use anyhow::Context; use diesel::result::Error::NotFound; -use lemmy_db::{ApubObject, Crud}; +use lemmy_db_queries::{ApubObject, Crud}; use lemmy_db_schema::source::{comment::Comment, post::Post, site::Site}; use lemmy_structs::blocking; use lemmy_utils::{location_info, LemmyError}; diff --git a/lemmy_apub/src/inbox/shared_inbox.rs b/lemmy_apub/src/inbox/shared_inbox.rs index d6c08a310..f9b9bfc01 100644 --- a/lemmy_apub/src/inbox/shared_inbox.rs +++ b/lemmy_apub/src/inbox/shared_inbox.rs @@ -15,7 +15,7 @@ use crate::{ use activitystreams::{activity::ActorAndObject, prelude::*}; use actix_web::{web, HttpRequest, HttpResponse}; use anyhow::Context; -use lemmy_db::{ApubObject, DbPool}; +use lemmy_db_queries::{ApubObject, DbPool}; use lemmy_db_schema::source::community::Community; use lemmy_structs::blocking; use lemmy_utils::{location_info, LemmyError}; diff --git a/lemmy_apub/src/inbox/user_inbox.rs b/lemmy_apub/src/inbox/user_inbox.rs index a9ca4b944..49c66dc7a 100644 --- a/lemmy_apub/src/inbox/user_inbox.rs +++ b/lemmy_apub/src/inbox/user_inbox.rs @@ -48,7 +48,7 @@ use activitystreams::{ use actix_web::{web, HttpRequest, HttpResponse}; use anyhow::{anyhow, Context}; use diesel::NotFound; -use lemmy_db::{source::user::User, ApubObject, Followable}; +use lemmy_db_queries::{source::user::User, ApubObject, Followable}; use lemmy_db_schema::source::{ community::{Community, CommunityFollower}, private_message::PrivateMessage, diff --git a/lemmy_apub/src/lib.rs b/lemmy_apub/src/lib.rs index 44786d171..6f0d41c8a 100644 --- a/lemmy_apub/src/lib.rs +++ b/lemmy_apub/src/lib.rs @@ -22,7 +22,7 @@ use activitystreams::{ }; use activitystreams_ext::{Ext1, Ext2}; use anyhow::{anyhow, Context}; -use lemmy_db::{source::activity::Activity_, DbPool}; +use lemmy_db_queries::{source::activity::Activity_, DbPool}; use lemmy_db_schema::source::{activity::Activity, user::User_}; use lemmy_structs::blocking; use lemmy_utils::{location_info, settings::Settings, LemmyError}; diff --git a/lemmy_apub/src/objects/comment.rs b/lemmy_apub/src/objects/comment.rs index e92272485..c02055c45 100644 --- a/lemmy_apub/src/objects/comment.rs +++ b/lemmy_apub/src/objects/comment.rs @@ -23,7 +23,7 @@ use activitystreams::{ prelude::*, }; use anyhow::{anyhow, Context}; -use lemmy_db::{Crud, DbPool}; +use lemmy_db_queries::{Crud, DbPool}; use lemmy_db_schema::source::{ comment::{Comment, CommentForm}, community::Community, diff --git a/lemmy_apub/src/objects/community.rs b/lemmy_apub/src/objects/community.rs index f4910716a..39abcd1f3 100644 --- a/lemmy_apub/src/objects/community.rs +++ b/lemmy_apub/src/objects/community.rs @@ -22,12 +22,12 @@ use activitystreams::{ }; use activitystreams_ext::Ext2; use anyhow::Context; -use lemmy_db::DbPool; +use lemmy_db_queries::DbPool; use lemmy_db_schema::{ naive_now, source::community::{Community, CommunityForm}, }; -use lemmy_db_views::community::community_moderator_view::CommunityModeratorView; +use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView; use lemmy_structs::blocking; use lemmy_utils::{ location_info, diff --git a/lemmy_apub/src/objects/mod.rs b/lemmy_apub/src/objects/mod.rs index 898c50f31..9e13782c9 100644 --- a/lemmy_apub/src/objects/mod.rs +++ b/lemmy_apub/src/objects/mod.rs @@ -11,7 +11,7 @@ use activitystreams::{ }; use anyhow::{anyhow, Context}; use chrono::NaiveDateTime; -use lemmy_db::{ApubObject, Crud, DbPool}; +use lemmy_db_queries::{ApubObject, Crud, DbPool}; use lemmy_structs::blocking; use lemmy_utils::{location_info, settings::Settings, utils::convert_datetime, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/objects/post.rs b/lemmy_apub/src/objects/post.rs index 499ac8020..fa1adfc84 100644 --- a/lemmy_apub/src/objects/post.rs +++ b/lemmy_apub/src/objects/post.rs @@ -20,7 +20,7 @@ use activitystreams::{ }; use activitystreams_ext::Ext1; use anyhow::Context; -use lemmy_db::{Crud, DbPool}; +use lemmy_db_queries::{Crud, DbPool}; use lemmy_db_schema::source::{ community::Community, post::{Post, PostForm}, diff --git a/lemmy_apub/src/objects/private_message.rs b/lemmy_apub/src/objects/private_message.rs index 34f37c4cd..db5a06109 100644 --- a/lemmy_apub/src/objects/private_message.rs +++ b/lemmy_apub/src/objects/private_message.rs @@ -19,7 +19,7 @@ use activitystreams::{ prelude::*, }; use anyhow::Context; -use lemmy_db::{Crud, DbPool}; +use lemmy_db_queries::{Crud, DbPool}; use lemmy_db_schema::source::{ private_message::{PrivateMessage, PrivateMessageForm}, user::User_, diff --git a/lemmy_apub/src/objects/user.rs b/lemmy_apub/src/objects/user.rs index 3ec1548d4..aad407f30 100644 --- a/lemmy_apub/src/objects/user.rs +++ b/lemmy_apub/src/objects/user.rs @@ -18,7 +18,7 @@ use activitystreams::{ }; use activitystreams_ext::Ext1; use anyhow::Context; -use lemmy_db::{ApubObject, DbPool}; +use lemmy_db_queries::{ApubObject, DbPool}; use lemmy_db_schema::{ naive_now, source::user::{UserForm, User_}, diff --git a/lemmy_db_queries/Cargo.toml b/lemmy_db_queries/Cargo.toml index eb633c7d1..f39d89b02 100644 --- a/lemmy_db_queries/Cargo.toml +++ b/lemmy_db_queries/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2018" [lib] -name = "lemmy_db" +name = "lemmy_db_queries" path = "src/lib.rs" [dependencies] diff --git a/lemmy_db_aggregates/src/comment_aggregates.rs b/lemmy_db_queries/src/aggregates/comment_aggregates.rs similarity index 97% rename from lemmy_db_aggregates/src/comment_aggregates.rs rename to lemmy_db_queries/src/aggregates/comment_aggregates.rs index 611ec287c..f6da44b0c 100644 --- a/lemmy_db_aggregates/src/comment_aggregates.rs +++ b/lemmy_db_queries/src/aggregates/comment_aggregates.rs @@ -22,8 +22,14 @@ impl CommentAggregates { #[cfg(test)] mod tests { - use crate::comment_aggregates::CommentAggregates; - use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType}; + use crate::{ + aggregates::comment_aggregates::CommentAggregates, + establish_unpooled_connection, + Crud, + Likeable, + ListingType, + SortType, + }; use lemmy_db_schema::source::{ comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, community::{Community, CommunityForm}, diff --git a/lemmy_db_aggregates/src/community_aggregates.rs b/lemmy_db_queries/src/aggregates/community_aggregates.rs similarity index 97% rename from lemmy_db_aggregates/src/community_aggregates.rs rename to lemmy_db_queries/src/aggregates/community_aggregates.rs index d6491546c..f34bd88b6 100644 --- a/lemmy_db_aggregates/src/community_aggregates.rs +++ b/lemmy_db_queries/src/aggregates/community_aggregates.rs @@ -22,8 +22,14 @@ impl CommunityAggregates { #[cfg(test)] mod tests { - use crate::community_aggregates::CommunityAggregates; - use lemmy_db::{establish_unpooled_connection, Crud, Followable, ListingType, SortType}; + use crate::{ + aggregates::community_aggregates::CommunityAggregates, + establish_unpooled_connection, + Crud, + Followable, + ListingType, + SortType, + }; use lemmy_db_schema::source::{ comment::{Comment, CommentForm}, community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm}, diff --git a/lemmy_db_aggregates/src/lib.rs b/lemmy_db_queries/src/aggregates/mod.rs similarity index 100% rename from lemmy_db_aggregates/src/lib.rs rename to lemmy_db_queries/src/aggregates/mod.rs diff --git a/lemmy_db_aggregates/src/post_aggregates.rs b/lemmy_db_queries/src/aggregates/post_aggregates.rs similarity index 97% rename from lemmy_db_aggregates/src/post_aggregates.rs rename to lemmy_db_queries/src/aggregates/post_aggregates.rs index e2d914085..5cfe0fdc8 100644 --- a/lemmy_db_aggregates/src/post_aggregates.rs +++ b/lemmy_db_queries/src/aggregates/post_aggregates.rs @@ -24,8 +24,14 @@ impl PostAggregates { #[cfg(test)] mod tests { - use crate::post_aggregates::PostAggregates; - use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType}; + use crate::{ + aggregates::post_aggregates::PostAggregates, + establish_unpooled_connection, + Crud, + Likeable, + ListingType, + SortType, + }; use lemmy_db_schema::source::{ comment::{Comment, CommentForm}, community::{Community, CommunityForm}, diff --git a/lemmy_db_aggregates/src/site_aggregates.rs b/lemmy_db_queries/src/aggregates/site_aggregates.rs similarity index 97% rename from lemmy_db_aggregates/src/site_aggregates.rs rename to lemmy_db_queries/src/aggregates/site_aggregates.rs index 559c5b53d..b12e2b60a 100644 --- a/lemmy_db_aggregates/src/site_aggregates.rs +++ b/lemmy_db_queries/src/aggregates/site_aggregates.rs @@ -21,8 +21,13 @@ impl SiteAggregates { #[cfg(test)] mod tests { - use crate::site_aggregates::SiteAggregates; - use lemmy_db::{establish_unpooled_connection, Crud, ListingType, SortType}; + use crate::{ + aggregates::site_aggregates::SiteAggregates, + establish_unpooled_connection, + Crud, + ListingType, + SortType, + }; use lemmy_db_schema::source::{ comment::{Comment, CommentForm}, community::{Community, CommunityForm}, diff --git a/lemmy_db_aggregates/src/user_aggregates.rs b/lemmy_db_queries/src/aggregates/user_aggregates.rs similarity index 97% rename from lemmy_db_aggregates/src/user_aggregates.rs rename to lemmy_db_queries/src/aggregates/user_aggregates.rs index cf5dfe69e..f11704567 100644 --- a/lemmy_db_aggregates/src/user_aggregates.rs +++ b/lemmy_db_queries/src/aggregates/user_aggregates.rs @@ -23,8 +23,14 @@ impl UserAggregates { #[cfg(test)] mod tests { - use crate::user_aggregates::UserAggregates; - use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType}; + use crate::{ + aggregates::user_aggregates::UserAggregates, + establish_unpooled_connection, + Crud, + Likeable, + ListingType, + SortType, + }; use lemmy_db_schema::source::{ comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, community::{Community, CommunityForm}, diff --git a/lemmy_db_queries/src/lib.rs b/lemmy_db_queries/src/lib.rs index 6f4c62c7f..b9dbc09d5 100644 --- a/lemmy_db_queries/src/lib.rs +++ b/lemmy_db_queries/src/lib.rs @@ -14,6 +14,7 @@ use regex::Regex; use serde::{Deserialize, Serialize}; use std::{env, env::VarError}; +pub mod aggregates; pub mod source; pub type DbPool = diesel::r2d2::Pool>; @@ -136,6 +137,13 @@ pub trait ToSafe { fn safe_columns_tuple() -> Self::SafeColumns; } +pub trait ViewToVec { + type DbTuple; + fn to_vec(tuple: Vec) -> Vec + where + Self: Sized; +} + pub fn get_database_url_from_env() -> Result { env::var("LEMMY_DATABASE_URL") } diff --git a/lemmy_db_schema/src/source/comment_report.rs b/lemmy_db_schema/src/source/comment_report.rs index d94fed578..ec53408d1 100644 --- a/lemmy_db_schema/src/source/comment_report.rs +++ b/lemmy_db_schema/src/source/comment_report.rs @@ -1,7 +1,9 @@ use crate::{schema::comment_report, source::comment::Comment}; use serde::{Deserialize, Serialize}; -#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)] +#[derive( + Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone, +)] #[belongs_to(Comment)] #[table_name = "comment_report"] pub struct CommentReport { diff --git a/lemmy_db_schema/src/source/post_report.rs b/lemmy_db_schema/src/source/post_report.rs index 608104dbc..b75fb954a 100644 --- a/lemmy_db_schema/src/source/post_report.rs +++ b/lemmy_db_schema/src/source/post_report.rs @@ -1,7 +1,9 @@ use crate::{schema::post_report, source::post::Post}; use serde::{Deserialize, Serialize}; -#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)] +#[derive( + Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone, +)] #[belongs_to(Post)] #[table_name = "post_report"] pub struct PostReport { diff --git a/lemmy_db_views/Cargo.toml b/lemmy_db_views/Cargo.toml index 86c7ada15..1353ddf3a 100644 --- a/lemmy_db_views/Cargo.toml +++ b/lemmy_db_views/Cargo.toml @@ -6,6 +6,5 @@ edition = "2018" [dependencies] lemmy_db_queries = { path = "../lemmy_db_queries" } lemmy_db_schema = { path = "../lemmy_db_schema" } -lemmy_db_aggregates = { path = "../lemmy_db_aggregates" } diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] } serde = { version = "1.0.118", features = ["derive"] } \ No newline at end of file diff --git a/lemmy_db_views/src/comment_report_view.rs b/lemmy_db_views/src/comment_report_view.rs index fa795a0bf..8e974f16e 100644 --- a/lemmy_db_views/src/comment_report_view.rs +++ b/lemmy_db_views/src/comment_report_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{limit_and_offset, MaybeOptional, ToSafe}; +use lemmy_db_queries::{limit_and_offset, MaybeOptional, ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{comment, comment_report, community, post, user_, user_alias_1, user_alias_2}, source::{ diff --git a/lemmy_db_views/src/comment_view.rs b/lemmy_db_views/src/comment_view.rs index 3101fcea8..064a8d4fa 100644 --- a/lemmy_db_views/src/comment_view.rs +++ b/lemmy_db_views/src/comment_view.rs @@ -1,6 +1,6 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{ +use lemmy_db_queries::{ + aggregates::comment_aggregates::CommentAggregates, functions::hot_rank, fuzzy_search, limit_and_offset, @@ -8,8 +8,8 @@ use lemmy_db::{ MaybeOptional, SortType, ToSafe, + ViewToVec, }; -use lemmy_db_aggregates::comment_aggregates::CommentAggregates; use lemmy_db_schema::{ schema::{ comment, @@ -419,8 +419,14 @@ impl ViewToVec for CommentView { #[cfg(test)] mod tests { use crate::comment_view::*; - use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType}; - use lemmy_db_aggregates::comment_aggregates::CommentAggregates; + use lemmy_db_queries::{ + aggregates::comment_aggregates::CommentAggregates, + establish_unpooled_connection, + Crud, + Likeable, + ListingType, + SortType, + }; use lemmy_db_schema::source::{comment::*, community::*, post::*, user::*}; #[test] diff --git a/lemmy_db_views/src/lib.rs b/lemmy_db_views/src/lib.rs index 3cac0bd3d..b46ec5a46 100644 --- a/lemmy_db_views/src/lib.rs +++ b/lemmy_db_views/src/lib.rs @@ -1,17 +1,6 @@ pub mod comment_report_view; pub mod comment_view; -pub mod community; -pub mod moderator; pub mod post_report_view; pub mod post_view; pub mod private_message_view; pub mod site_view; -pub mod user_mention_view; -pub mod user_view; - -pub(crate) trait ViewToVec { - type DbTuple; - fn to_vec(tuple: Vec) -> Vec - where - Self: Sized; -} diff --git a/lemmy_db_views/src/post_report_view.rs b/lemmy_db_views/src/post_report_view.rs index 3e0ef3d68..4f2db6bd2 100644 --- a/lemmy_db_views/src/post_report_view.rs +++ b/lemmy_db_views/src/post_report_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{limit_and_offset, MaybeOptional, ToSafe}; +use lemmy_db_queries::{limit_and_offset, MaybeOptional, ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{community, post, post_report, user_, user_alias_1, user_alias_2}, source::{ diff --git a/lemmy_db_views/src/post_view.rs b/lemmy_db_views/src/post_view.rs index fe1159274..9ce1af72e 100644 --- a/lemmy_db_views/src/post_view.rs +++ b/lemmy_db_views/src/post_view.rs @@ -1,6 +1,6 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{ +use lemmy_db_queries::{ + aggregates::post_aggregates::PostAggregates, functions::hot_rank, fuzzy_search, limit_and_offset, @@ -8,8 +8,8 @@ use lemmy_db::{ MaybeOptional, SortType, ToSafe, + ViewToVec, }; -use lemmy_db_aggregates::post_aggregates::PostAggregates; use lemmy_db_schema::{ schema::{ community, @@ -407,8 +407,14 @@ impl ViewToVec for PostView { #[cfg(test)] mod tests { use crate::post_view::{PostQueryBuilder, PostView}; - use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType}; - use lemmy_db_aggregates::post_aggregates::PostAggregates; + use lemmy_db_queries::{ + aggregates::post_aggregates::PostAggregates, + establish_unpooled_connection, + Crud, + Likeable, + ListingType, + SortType, + }; use lemmy_db_schema::source::{community::*, post::*, user::*}; #[test] diff --git a/lemmy_db_views/src/private_message_view.rs b/lemmy_db_views/src/private_message_view.rs index 62cb78987..945a46295 100644 --- a/lemmy_db_views/src/private_message_view.rs +++ b/lemmy_db_views/src/private_message_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{limit_and_offset, MaybeOptional, ToSafe}; +use lemmy_db_queries::{limit_and_offset, MaybeOptional, ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{private_message, user_, user_alias_1}, source::{ diff --git a/lemmy_db_views/src/site_view.rs b/lemmy_db_views/src/site_view.rs index a4c533e05..c04e85e9c 100644 --- a/lemmy_db_views/src/site_view.rs +++ b/lemmy_db_views/src/site_view.rs @@ -1,6 +1,5 @@ use diesel::{result::Error, *}; -use lemmy_db::ToSafe; -use lemmy_db_aggregates::site_aggregates::SiteAggregates; +use lemmy_db_queries::{aggregates::site_aggregates::SiteAggregates, ToSafe}; use lemmy_db_schema::{ schema::{site, site_aggregates, user_}, source::{ diff --git a/lemmy_db_aggregates/Cargo.toml b/lemmy_db_views_actor/Cargo.toml similarity index 78% rename from lemmy_db_aggregates/Cargo.toml rename to lemmy_db_views_actor/Cargo.toml index 6fdd77fde..92c2aafe9 100644 --- a/lemmy_db_aggregates/Cargo.toml +++ b/lemmy_db_views_actor/Cargo.toml @@ -1,11 +1,10 @@ [package] -name = "lemmy_db_aggregates" +name = "lemmy_db_views_actor" version = "0.1.0" edition = "2018" [dependencies] -lemmy_db_schema = { path = "../lemmy_db_schema" } lemmy_db_queries = { path = "../lemmy_db_queries" } +lemmy_db_schema = { path = "../lemmy_db_schema" } diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] } serde = { version = "1.0.118", features = ["derive"] } -chrono = { version = "0.4.19", features = ["serde"] } diff --git a/lemmy_db_views/src/community/community_follower_view.rs b/lemmy_db_views_actor/src/community_follower_view.rs similarity index 97% rename from lemmy_db_views/src/community/community_follower_view.rs rename to lemmy_db_views_actor/src/community_follower_view.rs index 9837624cb..a281a3feb 100644 --- a/lemmy_db_views/src/community/community_follower_view.rs +++ b/lemmy_db_views_actor/src/community_follower_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::ToSafe; +use lemmy_db_queries::{ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{community, community_follower, user_}, source::{ diff --git a/lemmy_db_views/src/community/community_moderator_view.rs b/lemmy_db_views_actor/src/community_moderator_view.rs similarity index 97% rename from lemmy_db_views/src/community/community_moderator_view.rs rename to lemmy_db_views_actor/src/community_moderator_view.rs index 490105d8b..30cbeb211 100644 --- a/lemmy_db_views/src/community/community_moderator_view.rs +++ b/lemmy_db_views_actor/src/community_moderator_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::ToSafe; +use lemmy_db_queries::{ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{community, community_moderator, user_}, source::{ diff --git a/lemmy_db_views/src/community/community_user_ban_view.rs b/lemmy_db_views_actor/src/community_user_ban_view.rs similarity index 97% rename from lemmy_db_views/src/community/community_user_ban_view.rs rename to lemmy_db_views_actor/src/community_user_ban_view.rs index ddc902766..d0a925848 100644 --- a/lemmy_db_views/src/community/community_user_ban_view.rs +++ b/lemmy_db_views_actor/src/community_user_ban_view.rs @@ -1,5 +1,5 @@ use diesel::{result::Error, *}; -use lemmy_db::ToSafe; +use lemmy_db_queries::ToSafe; use lemmy_db_schema::{ schema::{community, community_user_ban, user_}, source::{ diff --git a/lemmy_db_views/src/community/community_view.rs b/lemmy_db_views_actor/src/community_view.rs similarity index 97% rename from lemmy_db_views/src/community/community_view.rs rename to lemmy_db_views_actor/src/community_view.rs index fe87e2c78..d96b3aa99 100644 --- a/lemmy_db_views/src/community/community_view.rs +++ b/lemmy_db_views_actor/src/community_view.rs @@ -1,18 +1,15 @@ -use crate::{ - community::community_moderator_view::CommunityModeratorView, - user_view::UserViewSafe, - ViewToVec, -}; +use crate::{community_moderator_view::CommunityModeratorView, user_view::UserViewSafe}; use diesel::{result::Error, *}; -use lemmy_db::{ +use lemmy_db_queries::{ + aggregates::community_aggregates::CommunityAggregates, functions::hot_rank, fuzzy_search, limit_and_offset, MaybeOptional, SortType, ToSafe, + ViewToVec, }; -use lemmy_db_aggregates::community_aggregates::CommunityAggregates; use lemmy_db_schema::{ schema::{category, community, community_aggregates, community_follower, user_}, source::{ diff --git a/lemmy_db_views/src/community/mod.rs b/lemmy_db_views_actor/src/lib.rs similarity index 72% rename from lemmy_db_views/src/community/mod.rs rename to lemmy_db_views_actor/src/lib.rs index 491dde7f5..a2ac31937 100644 --- a/lemmy_db_views/src/community/mod.rs +++ b/lemmy_db_views_actor/src/lib.rs @@ -2,3 +2,5 @@ pub mod community_follower_view; pub mod community_moderator_view; pub mod community_user_ban_view; pub mod community_view; +pub mod user_mention_view; +pub mod user_view; diff --git a/lemmy_db_views/src/user_mention_view.rs b/lemmy_db_views_actor/src/user_mention_view.rs similarity index 98% rename from lemmy_db_views/src/user_mention_view.rs rename to lemmy_db_views_actor/src/user_mention_view.rs index f6afd298a..fd870c058 100644 --- a/lemmy_db_views/src/user_mention_view.rs +++ b/lemmy_db_views_actor/src/user_mention_view.rs @@ -1,7 +1,13 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{functions::hot_rank, limit_and_offset, MaybeOptional, SortType, ToSafe}; -use lemmy_db_aggregates::comment_aggregates::CommentAggregates; +use lemmy_db_queries::{ + aggregates::comment_aggregates::CommentAggregates, + functions::hot_rank, + limit_and_offset, + MaybeOptional, + SortType, + ToSafe, + ViewToVec, +}; use lemmy_db_schema::{ schema::{ comment, diff --git a/lemmy_db_views/src/user_view.rs b/lemmy_db_views_actor/src/user_view.rs similarity index 96% rename from lemmy_db_views/src/user_view.rs rename to lemmy_db_views_actor/src/user_view.rs index 5e5e7f2c1..4412b4fe6 100644 --- a/lemmy_db_views/src/user_view.rs +++ b/lemmy_db_views_actor/src/user_view.rs @@ -1,7 +1,13 @@ -use crate::ViewToVec; use diesel::{dsl::*, result::Error, *}; -use lemmy_db::{fuzzy_search, limit_and_offset, MaybeOptional, SortType, ToSafe}; -use lemmy_db_aggregates::user_aggregates::UserAggregates; +use lemmy_db_queries::{ + aggregates::user_aggregates::UserAggregates, + fuzzy_search, + limit_and_offset, + MaybeOptional, + SortType, + ToSafe, + ViewToVec, +}; use lemmy_db_schema::{ schema::{user_, user_aggregates}, source::user::{UserSafe, User_}, diff --git a/lemmy_db_views_moderator/Cargo.toml b/lemmy_db_views_moderator/Cargo.toml new file mode 100644 index 000000000..7df6844ad --- /dev/null +++ b/lemmy_db_views_moderator/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "lemmy_db_views_moderator" +version = "0.1.0" +edition = "2018" + +[dependencies] +lemmy_db_queries = { path = "../lemmy_db_queries" } +lemmy_db_schema = { path = "../lemmy_db_schema" } +diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] } +serde = { version = "1.0.118", features = ["derive"] } diff --git a/lemmy_db_views/src/moderator/mod.rs b/lemmy_db_views_moderator/src/lib.rs similarity index 100% rename from lemmy_db_views/src/moderator/mod.rs rename to lemmy_db_views_moderator/src/lib.rs diff --git a/lemmy_db_views/src/moderator/mod_add_community_view.rs b/lemmy_db_views_moderator/src/mod_add_community_view.rs similarity index 97% rename from lemmy_db_views/src/moderator/mod_add_community_view.rs rename to lemmy_db_views_moderator/src/mod_add_community_view.rs index 606ee51e8..a95785834 100644 --- a/lemmy_db_views/src/moderator/mod_add_community_view.rs +++ b/lemmy_db_views_moderator/src/mod_add_community_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{limit_and_offset, ToSafe}; +use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{community, mod_add_community, user_, user_alias_1}, source::{ diff --git a/lemmy_db_views/src/moderator/mod_add_view.rs b/lemmy_db_views_moderator/src/mod_add_view.rs similarity index 96% rename from lemmy_db_views/src/moderator/mod_add_view.rs rename to lemmy_db_views_moderator/src/mod_add_view.rs index efe33fd3c..9e2507b28 100644 --- a/lemmy_db_views/src/moderator/mod_add_view.rs +++ b/lemmy_db_views_moderator/src/mod_add_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{limit_and_offset, ToSafe}; +use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{mod_add, user_, user_alias_1}, source::{ diff --git a/lemmy_db_views/src/moderator/mod_ban_from_community_view.rs b/lemmy_db_views_moderator/src/mod_ban_from_community_view.rs similarity index 97% rename from lemmy_db_views/src/moderator/mod_ban_from_community_view.rs rename to lemmy_db_views_moderator/src/mod_ban_from_community_view.rs index 430259a41..b914127b8 100644 --- a/lemmy_db_views/src/moderator/mod_ban_from_community_view.rs +++ b/lemmy_db_views_moderator/src/mod_ban_from_community_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{limit_and_offset, ToSafe}; +use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{community, mod_ban_from_community, user_, user_alias_1}, source::{ diff --git a/lemmy_db_views/src/moderator/mod_ban_view.rs b/lemmy_db_views_moderator/src/mod_ban_view.rs similarity index 96% rename from lemmy_db_views/src/moderator/mod_ban_view.rs rename to lemmy_db_views_moderator/src/mod_ban_view.rs index f61a04219..730212fa1 100644 --- a/lemmy_db_views/src/moderator/mod_ban_view.rs +++ b/lemmy_db_views_moderator/src/mod_ban_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{limit_and_offset, ToSafe}; +use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{mod_ban, user_, user_alias_1}, source::{ diff --git a/lemmy_db_views/src/moderator/mod_lock_post_view.rs b/lemmy_db_views_moderator/src/mod_lock_post_view.rs similarity index 96% rename from lemmy_db_views/src/moderator/mod_lock_post_view.rs rename to lemmy_db_views_moderator/src/mod_lock_post_view.rs index 11521329e..2feea8319 100644 --- a/lemmy_db_views/src/moderator/mod_lock_post_view.rs +++ b/lemmy_db_views_moderator/src/mod_lock_post_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{limit_and_offset, ToSafe}; +use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{community, mod_lock_post, post, user_}, source::{ diff --git a/lemmy_db_views/src/moderator/mod_remove_comment_view.rs b/lemmy_db_views_moderator/src/mod_remove_comment_view.rs similarity index 97% rename from lemmy_db_views/src/moderator/mod_remove_comment_view.rs rename to lemmy_db_views_moderator/src/mod_remove_comment_view.rs index 0c52be2f9..87715c757 100644 --- a/lemmy_db_views/src/moderator/mod_remove_comment_view.rs +++ b/lemmy_db_views_moderator/src/mod_remove_comment_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{limit_and_offset, ToSafe}; +use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{comment, community, mod_remove_comment, post, user_, user_alias_1}, source::{ diff --git a/lemmy_db_views/src/moderator/mod_remove_community_view.rs b/lemmy_db_views_moderator/src/mod_remove_community_view.rs similarity index 96% rename from lemmy_db_views/src/moderator/mod_remove_community_view.rs rename to lemmy_db_views_moderator/src/mod_remove_community_view.rs index 86fcf1954..491827bfb 100644 --- a/lemmy_db_views/src/moderator/mod_remove_community_view.rs +++ b/lemmy_db_views_moderator/src/mod_remove_community_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{limit_and_offset, ToSafe}; +use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{community, mod_remove_community, user_}, source::{ diff --git a/lemmy_db_views/src/moderator/mod_remove_post_view.rs b/lemmy_db_views_moderator/src/mod_remove_post_view.rs similarity index 96% rename from lemmy_db_views/src/moderator/mod_remove_post_view.rs rename to lemmy_db_views_moderator/src/mod_remove_post_view.rs index d4332918f..b524206ba 100644 --- a/lemmy_db_views/src/moderator/mod_remove_post_view.rs +++ b/lemmy_db_views_moderator/src/mod_remove_post_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{limit_and_offset, ToSafe}; +use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{community, mod_remove_post, post, user_}, source::{ diff --git a/lemmy_db_views/src/moderator/mod_sticky_post_view.rs b/lemmy_db_views_moderator/src/mod_sticky_post_view.rs similarity index 96% rename from lemmy_db_views/src/moderator/mod_sticky_post_view.rs rename to lemmy_db_views_moderator/src/mod_sticky_post_view.rs index ec785ce1b..4053b8ab3 100644 --- a/lemmy_db_views/src/moderator/mod_sticky_post_view.rs +++ b/lemmy_db_views_moderator/src/mod_sticky_post_view.rs @@ -1,6 +1,5 @@ -use crate::ViewToVec; use diesel::{result::Error, *}; -use lemmy_db::{limit_and_offset, ToSafe}; +use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec}; use lemmy_db_schema::{ schema::{community, mod_sticky_post, post, user_}, source::{ diff --git a/lemmy_rate_limit/Cargo.toml b/lemmy_rate_limit/Cargo.toml deleted file mode 100644 index 5574efadb..000000000 --- a/lemmy_rate_limit/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "lemmy_rate_limit" -version = "0.1.0" -authors = ["Felix Ableitner "] -edition = "2018" - -[lib] -name = "lemmy_rate_limit" -path = "src/lib.rs" - -[dependencies] -lemmy_utils = { path = "../lemmy_utils" } -tokio = { version = "0.3.6", features = ["sync"] } -strum = "0.20.0" -strum_macros = "0.20.1" -futures = "0.3.8" -actix-web = { version = "3.3.2", default-features = false, features = ["rustls"] } -log = "0.4.11" diff --git a/lemmy_structs/Cargo.toml b/lemmy_structs/Cargo.toml index d4f013b92..b6ecade51 100644 --- a/lemmy_structs/Cargo.toml +++ b/lemmy_structs/Cargo.toml @@ -11,6 +11,8 @@ path = "src/lib.rs" [dependencies] lemmy_db_queries = { path = "../lemmy_db_queries" } lemmy_db_views = { path = "../lemmy_db_views" } +lemmy_db_views_moderator = { path = "../lemmy_db_views_moderator" } +lemmy_db_views_actor = { path = "../lemmy_db_views_actor" } lemmy_db_schema = { path = "../lemmy_db_schema" } lemmy_utils = { path = "../lemmy_utils" } serde = { version = "1.0.118", features = ["derive"] } diff --git a/lemmy_structs/src/community.rs b/lemmy_structs/src/community.rs index 74f7a4e42..8c45cc9f3 100644 --- a/lemmy_structs/src/community.rs +++ b/lemmy_structs/src/community.rs @@ -1,9 +1,7 @@ -use lemmy_db_views::{ - community::{ - community_follower_view::CommunityFollowerView, - community_moderator_view::CommunityModeratorView, - community_view::CommunityView, - }, +use lemmy_db_views_actor::{ + community_follower_view::CommunityFollowerView, + community_moderator_view::CommunityModeratorView, + community_view::CommunityView, user_view::UserViewSafe, }; use serde::{Deserialize, Serialize}; diff --git a/lemmy_structs/src/lib.rs b/lemmy_structs/src/lib.rs index 080cb3852..546eb4ee1 100644 --- a/lemmy_structs/src/lib.rs +++ b/lemmy_structs/src/lib.rs @@ -5,7 +5,7 @@ pub mod site; pub mod user; use diesel::PgConnection; -use lemmy_db::{source::user::User, Crud, DbPool}; +use lemmy_db_queries::{source::user::User, Crud, DbPool}; use lemmy_db_schema::source::{ comment::Comment, post::Post, diff --git a/lemmy_structs/src/post.rs b/lemmy_structs/src/post.rs index 5a35fa37e..0410b1b82 100644 --- a/lemmy_structs/src/post.rs +++ b/lemmy_structs/src/post.rs @@ -1,9 +1,9 @@ use lemmy_db_views::{ comment_view::CommentView, - community::community_moderator_view::CommunityModeratorView, post_report_view::PostReportView, post_view::PostView, }; +use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Debug)] diff --git a/lemmy_structs/src/site.rs b/lemmy_structs/src/site.rs index fbb295d51..e30523464 100644 --- a/lemmy_structs/src/site.rs +++ b/lemmy_structs/src/site.rs @@ -1,21 +1,16 @@ use lemmy_db_schema::source::{category::*, user::User_}; -use lemmy_db_views::{ - comment_view::CommentView, - community::community_view::CommunityView, - moderator::{ - mod_add_community_view::ModAddCommunityView, - mod_add_view::ModAddView, - mod_ban_from_community_view::ModBanFromCommunityView, - mod_ban_view::ModBanView, - mod_lock_post_view::ModLockPostView, - mod_remove_comment_view::ModRemoveCommentView, - mod_remove_community_view::ModRemoveCommunityView, - mod_remove_post_view::ModRemovePostView, - mod_sticky_post_view::ModStickyPostView, - }, - post_view::PostView, - site_view::SiteView, - user_view::UserViewSafe, +use lemmy_db_views::{comment_view::CommentView, post_view::PostView, site_view::SiteView}; +use lemmy_db_views_actor::{community_view::CommunityView, user_view::UserViewSafe}; +use lemmy_db_views_moderator::{ + mod_add_community_view::ModAddCommunityView, + mod_add_view::ModAddView, + mod_ban_from_community_view::ModBanFromCommunityView, + mod_ban_view::ModBanView, + mod_lock_post_view::ModLockPostView, + mod_remove_comment_view::ModRemoveCommentView, + mod_remove_community_view::ModRemoveCommunityView, + mod_remove_post_view::ModRemovePostView, + mod_sticky_post_view::ModStickyPostView, }; use serde::{Deserialize, Serialize}; diff --git a/lemmy_structs/src/user.rs b/lemmy_structs/src/user.rs index 4b4d6a886..a3836f11f 100644 --- a/lemmy_structs/src/user.rs +++ b/lemmy_structs/src/user.rs @@ -1,11 +1,11 @@ use lemmy_db_views::{ comment_view::CommentView, - community::{ - community_follower_view::CommunityFollowerView, - community_moderator_view::CommunityModeratorView, - }, post_view::PostView, private_message_view::PrivateMessageView, +}; +use lemmy_db_views_actor::{ + community_follower_view::CommunityFollowerView, + community_moderator_view::CommunityModeratorView, user_mention_view::UserMentionView, user_view::{UserViewDangerous, UserViewSafe}, }; diff --git a/lemmy_utils/Cargo.toml b/lemmy_utils/Cargo.toml index fe810a79f..df4ae1b2b 100644 --- a/lemmy_utils/Cargo.toml +++ b/lemmy_utils/Cargo.toml @@ -27,3 +27,7 @@ actix-web = { version = "3.3.2", default-features = false, features = ["rustls"] actix-rt = { version = "1.1.1", default-features = false } anyhow = "1.0.36" reqwest = { version = "0.10.10", features = ["json"] } +tokio = { version = "0.3.6", features = ["sync"] } +strum = "0.20.0" +strum_macros = "0.20.1" +futures = "0.3.8" diff --git a/lemmy_utils/src/lib.rs b/lemmy_utils/src/lib.rs index eecb7b2d7..e0b8e3aa1 100644 --- a/lemmy_utils/src/lib.rs +++ b/lemmy_utils/src/lib.rs @@ -1,8 +1,11 @@ #[macro_use] extern crate lazy_static; +#[macro_use] +extern crate strum_macros; pub mod apub; pub mod email; +pub mod rate_limit; pub mod request; pub mod settings; #[cfg(test)] diff --git a/lemmy_rate_limit/src/lib.rs b/lemmy_utils/src/rate_limit/mod.rs similarity index 98% rename from lemmy_rate_limit/src/lib.rs rename to lemmy_utils/src/rate_limit/mod.rs index ecb812af8..5a18ffd54 100644 --- a/lemmy_rate_limit/src/lib.rs +++ b/lemmy_utils/src/rate_limit/mod.rs @@ -1,13 +1,10 @@ -#[macro_use] -extern crate strum_macros; - -use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform}; -use futures::future::{ok, Ready}; -use lemmy_utils::{ +use crate::{ settings::{RateLimitConfig, Settings}, utils::get_ip, LemmyError, }; +use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform}; +use futures::future::{ok, Ready}; use rate_limiter::{RateLimitType, RateLimiter}; use std::{ future::Future, diff --git a/lemmy_rate_limit/src/rate_limiter.rs b/lemmy_utils/src/rate_limit/rate_limiter.rs similarity index 98% rename from lemmy_rate_limit/src/rate_limiter.rs rename to lemmy_utils/src/rate_limit/rate_limiter.rs index bd089febd..5bb02f596 100644 --- a/lemmy_rate_limit/src/rate_limiter.rs +++ b/lemmy_utils/src/rate_limit/rate_limiter.rs @@ -1,4 +1,4 @@ -use lemmy_utils::{APIError, IPAddr, LemmyError}; +use crate::{APIError, IPAddr, LemmyError}; use log::debug; use std::{collections::HashMap, time::SystemTime}; use strum::IntoEnumIterator; diff --git a/lemmy_websocket/Cargo.toml b/lemmy_websocket/Cargo.toml index 4f036ae52..944760c2d 100644 --- a/lemmy_websocket/Cargo.toml +++ b/lemmy_websocket/Cargo.toml @@ -13,7 +13,6 @@ lemmy_utils = { path = "../lemmy_utils" } lemmy_structs = { path = "../lemmy_structs" } lemmy_db_queries = { path = "../lemmy_db_queries" } lemmy_db_schema = { path = "../lemmy_db_schema" } -lemmy_rate_limit = { path = "../lemmy_rate_limit" } reqwest = { version = "0.10.10", features = ["json"] } log = "0.4.11" rand = "0.8.0" diff --git a/lemmy_websocket/src/chat_server.rs b/lemmy_websocket/src/chat_server.rs index ece5d3534..f149d6e1e 100644 --- a/lemmy_websocket/src/chat_server.rs +++ b/lemmy_websocket/src/chat_server.rs @@ -6,10 +6,10 @@ use diesel::{ r2d2::{ConnectionManager, Pool}, PgConnection, }; -use lemmy_rate_limit::RateLimit; use lemmy_structs::{comment::*, post::*}; use lemmy_utils::{ location_info, + rate_limit::RateLimit, APIError, CommunityId, ConnectionId, diff --git a/lemmy_websocket/src/lib.rs b/lemmy_websocket/src/lib.rs index d789efdd1..72e72b52f 100644 --- a/lemmy_websocket/src/lib.rs +++ b/lemmy_websocket/src/lib.rs @@ -4,7 +4,7 @@ extern crate strum_macros; use crate::chat_server::ChatServer; use actix::Addr; use background_jobs::QueueHandle; -use lemmy_db::DbPool; +use lemmy_db_queries::DbPool; use lemmy_utils::LemmyError; use reqwest::Client; use serde::Serialize; diff --git a/src/code_migrations.rs b/src/code_migrations.rs index 73b030cb2..d2928244e 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -3,7 +3,7 @@ use diesel::{ sql_types::{Nullable, Text}, *, }; -use lemmy_db::{ +use lemmy_db_queries::{ source::{comment::Comment_, post::Post_, private_message::PrivateMessage_}, Crud, }; diff --git a/src/main.rs b/src/main.rs index c55c3655d..fad3680bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,11 +9,14 @@ use diesel::{ }; use lemmy_api::match_websocket_operation; use lemmy_apub::activity_queue::create_activity_queue; -use lemmy_db::get_database_url_from_env; -use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit}; +use lemmy_db_queries::get_database_url_from_env; use lemmy_server::{code_migrations::run_advanced_migrations, routes::*}; use lemmy_structs::blocking; -use lemmy_utils::{settings::Settings, LemmyError}; +use lemmy_utils::{ + rate_limit::{rate_limiter::RateLimiter, RateLimit}, + settings::Settings, + LemmyError, +}; use lemmy_websocket::{chat_server::ChatServer, LemmyContext}; use reqwest::Client; use std::sync::Arc; diff --git a/src/routes/api.rs b/src/routes/api.rs index 199e14ac9..2a91b2c5f 100644 --- a/src/routes/api.rs +++ b/src/routes/api.rs @@ -1,7 +1,7 @@ use actix_web::{error::ErrorBadRequest, *}; use lemmy_api::Perform; -use lemmy_rate_limit::RateLimit; use lemmy_structs::{comment::*, community::*, post::*, site::*, user::*}; +use lemmy_utils::rate_limit::RateLimit; use lemmy_websocket::LemmyContext; use serde::Deserialize; diff --git a/src/routes/feeds.rs b/src/routes/feeds.rs index d7862dcd5..5065390c2 100644 --- a/src/routes/feeds.rs +++ b/src/routes/feeds.rs @@ -3,7 +3,7 @@ use anyhow::anyhow; use chrono::{DateTime, NaiveDateTime, Utc}; use diesel::PgConnection; use lemmy_api::claims::Claims; -use lemmy_db::{ +use lemmy_db_queries::{ source::{community::Community_, user::User}, ListingType, SortType, @@ -13,8 +13,8 @@ use lemmy_db_views::{ comment_view::{CommentQueryBuilder, CommentView}, post_view::{PostQueryBuilder, PostView}, site_view::SiteView, - user_mention_view::{UserMentionQueryBuilder, UserMentionView}, }; +use lemmy_db_views_actor::user_mention_view::{UserMentionQueryBuilder, UserMentionView}; use lemmy_structs::blocking; use lemmy_utils::{settings::Settings, utils::markdown_to_html, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/src/routes/images.rs b/src/routes/images.rs index e6f32b410..c9937ee68 100644 --- a/src/routes/images.rs +++ b/src/routes/images.rs @@ -2,8 +2,7 @@ use actix::clock::Duration; use actix_web::{body::BodyStream, http::StatusCode, *}; use awc::Client; use lemmy_api::claims::Claims; -use lemmy_rate_limit::RateLimit; -use lemmy_utils::settings::Settings; +use lemmy_utils::{rate_limit::RateLimit, settings::Settings}; use serde::{Deserialize, Serialize}; pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { diff --git a/src/routes/webfinger.rs b/src/routes/webfinger.rs index 2a03f5e2a..0e4d7f948 100644 --- a/src/routes/webfinger.rs +++ b/src/routes/webfinger.rs @@ -1,6 +1,6 @@ use actix_web::{error::ErrorBadRequest, web::Query, *}; use anyhow::anyhow; -use lemmy_db::source::{community::Community_, user::User}; +use lemmy_db_queries::source::{community::Community_, user::User}; use lemmy_db_schema::source::{community::Community, user::User_}; use lemmy_structs::{blocking, WebFingerLink, WebFingerResponse}; use lemmy_utils::{ diff --git a/tests/integration_test.rs b/tests/integration_test.rs index c507af067..d97cb72f2 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -28,13 +28,16 @@ use lemmy_apub::{ user_inbox::user_inbox, }, }; -use lemmy_db::{Crud, ListingType, SortType}; +use lemmy_db_queries::{Crud, ListingType, SortType}; use lemmy_db_schema::source::{ community::{Community, CommunityForm}, user::{UserForm, User_}, }; -use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit}; -use lemmy_utils::{apub::generate_actor_keypair, settings::Settings}; +use lemmy_utils::{ + apub::generate_actor_keypair, + rate_limit::{rate_limiter::RateLimiter, RateLimit}, + settings::Settings, +}; use lemmy_websocket::{chat_server::ChatServer, LemmyContext}; use reqwest::Client; use serde::{Deserialize, Serialize}; From 5a16d43fef431c85b17aaf06c9edec460cbde3b2 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 22 Dec 2020 13:03:50 +0100 Subject: [PATCH 3/3] Run cargo clippy in CI on whole workspace --- .drone.yml | 2 +- lemmy_db_views/src/post_view.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index 6a2630b53..eb5992234 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,7 +17,7 @@ steps: - name: cargo clippy image: ekidd/rust-musl-builder:1.47.0 commands: - - cargo clippy --all-targets --all-features -- -D warnings + - cargo clippy --workspace --all-targets --all-features -- -D warnings - name: check documentation build image: ekidd/rust-musl-builder:1.47.0 diff --git a/lemmy_db_views/src/post_view.rs b/lemmy_db_views/src/post_view.rs index 9ce1af72e..dcd6a9814 100644 --- a/lemmy_db_views/src/post_view.rs +++ b/lemmy_db_views/src/post_view.rs @@ -540,7 +540,7 @@ mod tests { let expected_post_listing_no_user = PostView { post: Post { id: inserted_post.id, - name: post_name.to_owned(), + name: post_name, creator_id: inserted_user.id, url: None, body: None, @@ -562,7 +562,7 @@ mod tests { my_vote: None, creator: UserSafe { id: inserted_user.id, - name: user_name.to_owned(), + name: user_name, preferred_username: None, published: inserted_user.published, avatar: None, @@ -579,7 +579,7 @@ mod tests { creator_banned_from_community: false, community: CommunitySafe { id: inserted_community.id, - name: community_name.to_owned(), + name: community_name, icon: None, removed: false, deleted: false,