From 95e30f0e08eb86d388a9d739844626d5c82a5078 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 22 Dec 2020 00:27:42 +0100 Subject: [PATCH] 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 dd16aa97..782458b1 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 f6234416..ca2d291c 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 b9bda599..e0766df3 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 eb8d68b7..840600cb 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 8c2d9ad5..f01e0740 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 72c2316d..c1dee7aa 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 6f514970..07a39732 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 dcf35c00..2f5f4a3a 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 90891154..91c3b11a 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 a912f448..a524daf1 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 483ef54f..7ba3a05c 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 4f845523..5dc021ad 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 f493a563..7f552377 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 2b46cf54..c35a0281 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 bf188a9f..0b9d6f4a 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 d2755094..bd21f4c7 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 4ddd2d32..3f7a59de 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 1a4a4a57..e148b4e9 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 732a53c3..4af40de2 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 bcbb303b..d920f3de 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 cad20e9d..049496f7 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 fe70d8e8..0dd7776f 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 2d8cfe79..b9790b23 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 e67fbc96..4e1fa98a 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 f71d542b..44397db6 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 011f2d88..668c90a3 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 5d45a725..0d77aed7 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 8ade3529..66adae3a 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 b01347e0..d3b1b4d4 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 e6d7b29c..1e44254c 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 9b200934..a91dd48e 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 31c5efba..93440424 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 d6c08a31..f9b9bfc0 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 a9ca4b94..49c66dc7 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 44786d17..6f0d41c8 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 e9227248..c02055c4 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 f4910716..39abcd1f 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 898c50f3..9e13782c 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 499ac802..fa1adfc8 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 34f37c4c..db5a0610 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 3ec1548d..aad407f3 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 eb633c7d..f39d89b0 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 611ec287..f6da44b0 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 d6491546..f34bd88b 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 e2d91408..5cfe0fdc 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 559c5b53..b12e2b60 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 cf5dfe69..f1170456 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 6f4c62c7..b9dbc09d 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 d94fed57..ec53408d 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 608104db..b75fb954 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 86c7ada1..1353ddf3 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 fa795a0b..8e974f16 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 3101fcea..064a8d4f 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 3cac0bd3..b46ec5a4 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 3e0ef3d6..4f2db6bd 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 fe115927..9ce1af72 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 62cb7898..945a4629 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 a4c533e0..c04e85e9 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 6fdd77fd..92c2aafe 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 9837624c..a281a3fe 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 490105d8..30cbeb21 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 ddc90276..d0a92584 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 fe87e2c7..d96b3aa9 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 491dde7f..a2ac3193 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 f6afd298..fd870c05 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 5e5e7f2c..4412b4fe 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 00000000..7df6844a --- /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 606ee51e..a9578583 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 efe33fd3..9e2507b2 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 430259a4..b914127b 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 f61a0421..730212fa 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 11521329..2feea831 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 0c52be2f..87715c75 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 86fcf195..491827bf 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 d4332918..b524206b 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 ec785ce1..4053b8ab 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 5574efad..00000000 --- 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 d4f013b9..b6ecade5 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 74f7a4e4..8c45cc9f 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 080cb385..546eb4ee 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 5a35fa37..0410b1b8 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 fbb295d5..e3052346 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 4b4d6a88..a3836f11 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 fe810a79..df4ae1b2 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 eecb7b2d..e0b8e3aa 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 ecb812af..5a18ffd5 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 bd089feb..5bb02f59 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 4f036ae5..944760c2 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 ece5d353..f149d6e1 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 d789efdd..72e72b52 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 73b030cb..d2928244 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 c55c3655..fad3680b 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 199e14ac..2a91b2c5 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 d7862dcd..5065390c 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 e6f32b41..c9937ee6 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 2a03f5e2..0e4d7f94 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 c507af06..d97cb72f 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}; -- 2.44.1