From: Dessalines Date: Tue, 30 Jun 2020 00:02:38 +0000 (-0400) Subject: Remove mat views, no fast tables or caching added yet. X-Git-Url: http://these/git/readmes/%7B%7D/static/%7B%60https:/%7Burl%7D?a=commitdiff_plain;h=97e088dcbfb91bb16bd0190f8d956095755e8cb4;p=lemmy.git Remove mat views, no fast tables or caching added yet. --- diff --git a/server/migrations/2020-06-29-222617_remove_mat_views/down.sql b/server/migrations/2020-06-29-222617_remove_mat_views/down.sql new file mode 100644 index 00000000..7c490863 --- /dev/null +++ b/server/migrations/2020-06-29-222617_remove_mat_views/down.sql @@ -0,0 +1,9 @@ +alter table comment enable trigger refresh_comment; +alter table user_ enable trigger refresh_user; +alter table post enable trigger refresh_post; +alter table community enable trigger refresh_community; +alter table private_message enable trigger refresh_private_message; +alter table post_like enable trigger refresh_post_like; +alter table community_follower enable trigger refresh_community_follower; +alter table community_user_ban enable trigger refresh_community_user_ban; +alter table comment_like enable trigger refresh_comment_like; diff --git a/server/migrations/2020-06-29-222617_remove_mat_views/up.sql b/server/migrations/2020-06-29-222617_remove_mat_views/up.sql new file mode 100644 index 00000000..eb0fb938 --- /dev/null +++ b/server/migrations/2020-06-29-222617_remove_mat_views/up.sql @@ -0,0 +1,9 @@ +alter table comment disable trigger refresh_comment; +alter table user_ disable trigger refresh_user; +alter table post disable trigger refresh_post; +alter table community disable trigger refresh_community; +alter table private_message disable trigger refresh_private_message; +alter table post_like disable trigger refresh_post_like; +alter table community_follower disable trigger refresh_community_follower; +alter table community_user_ban disable trigger refresh_community_user_ban; +alter table comment_like disable trigger refresh_comment_like; diff --git a/server/src/db/comment_view.rs b/server/src/db/comment_view.rs index a37cdbcd..f96d9534 100644 --- a/server/src/db/comment_view.rs +++ b/server/src/db/comment_view.rs @@ -38,41 +38,6 @@ table! { } } -table! { - comment_mview (id) { - id -> Int4, - creator_id -> Int4, - post_id -> Int4, - parent_id -> Nullable, - content -> Text, - removed -> Bool, - read -> Bool, - published -> Timestamp, - updated -> Nullable, - deleted -> Bool, - ap_id -> Text, - local -> Bool, - community_id -> Int4, - community_actor_id -> Text, - community_local -> Bool, - community_name -> Varchar, - banned -> Bool, - banned_from_community -> Bool, - creator_actor_id -> Text, - creator_local -> Bool, - creator_name -> Varchar, - creator_avatar -> Nullable, - score -> BigInt, - upvotes -> BigInt, - downvotes -> BigInt, - hot_rank -> Int4, - user_id -> Nullable, - my_vote -> Nullable, - subscribed -> Nullable, - saved -> Nullable, - } -} - #[derive( Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, )] @@ -112,7 +77,7 @@ pub struct CommentView { pub struct CommentQueryBuilder<'a> { conn: &'a PgConnection, - query: super::comment_view::comment_mview::BoxedQuery<'a, Pg>, + query: super::comment_view::comment_view::BoxedQuery<'a, Pg>, listing_type: ListingType, sort: &'a SortType, for_community_id: Option, @@ -127,9 +92,9 @@ pub struct CommentQueryBuilder<'a> { impl<'a> CommentQueryBuilder<'a> { pub fn create(conn: &'a PgConnection) -> Self { - use super::comment_view::comment_mview::dsl::*; + use super::comment_view::comment_view::dsl::*; - let query = comment_mview.into_boxed(); + let query = comment_view.into_boxed(); CommentQueryBuilder { conn, @@ -198,7 +163,7 @@ impl<'a> CommentQueryBuilder<'a> { } pub fn list(self) -> Result, Error> { - use super::comment_view::comment_mview::dsl::*; + use super::comment_view::comment_view::dsl::*; let mut query = self.query; @@ -270,8 +235,8 @@ impl CommentView { from_comment_id: i32, my_user_id: Option, ) -> Result { - use super::comment_view::comment_mview::dsl::*; - let mut query = comment_mview.into_boxed(); + use super::comment_view::comment_view::dsl::*; + let mut query = comment_view.into_boxed(); // The view lets you pass a null user_id, if you're not logged in if let Some(my_user_id) = my_user_id { diff --git a/server/src/db/community_view.rs b/server/src/db/community_view.rs index ea7b2a7c..606ec13c 100644 --- a/server/src/db/community_view.rs +++ b/server/src/db/community_view.rs @@ -1,4 +1,4 @@ -use super::community_view::community_mview::BoxedQuery; +use super::community_view::community_view::BoxedQuery; use crate::db::{fuzzy_search, limit_and_offset, MaybeOptional, SortType}; use diesel::{pg::Pg, result::Error, *}; use serde::{Deserialize, Serialize}; @@ -33,36 +33,6 @@ table! { } } -table! { - community_mview (id) { - id -> Int4, - name -> Varchar, - title -> Varchar, - description -> Nullable, - category_id -> Int4, - creator_id -> Int4, - removed -> Bool, - published -> Timestamp, - updated -> Nullable, - deleted -> Bool, - nsfw -> Bool, - actor_id -> Text, - local -> Bool, - last_refreshed_at -> Timestamp, - creator_actor_id -> Text, - creator_local -> Bool, - creator_name -> Varchar, - creator_avatar -> Nullable, - category_name -> Varchar, - number_of_subscribers -> BigInt, - number_of_posts -> BigInt, - number_of_comments -> BigInt, - hot_rank -> Int4, - user_id -> Nullable, - subscribed -> Nullable, - } -} - table! { community_moderator_view (id) { id -> Int4, @@ -156,9 +126,9 @@ pub struct CommunityQueryBuilder<'a> { impl<'a> CommunityQueryBuilder<'a> { pub fn create(conn: &'a PgConnection) -> Self { - use super::community_view::community_mview::dsl::*; + use super::community_view::community_view::dsl::*; - let query = community_mview.into_boxed(); + let query = community_view.into_boxed(); CommunityQueryBuilder { conn, @@ -203,7 +173,7 @@ impl<'a> CommunityQueryBuilder<'a> { } pub fn list(self) -> Result, Error> { - use super::community_view::community_mview::dsl::*; + use super::community_view::community_view::dsl::*; let mut query = self.query; @@ -259,9 +229,9 @@ impl CommunityView { from_community_id: i32, from_user_id: Option, ) -> Result { - use super::community_view::community_mview::dsl::*; + use super::community_view::community_view::dsl::*; - let mut query = community_mview.into_boxed(); + let mut query = community_view.into_boxed(); query = query.filter(id.eq(from_community_id)); diff --git a/server/src/db/post_view.rs b/server/src/db/post_view.rs index fbbf658d..6865402f 100644 --- a/server/src/db/post_view.rs +++ b/server/src/db/post_view.rs @@ -1,4 +1,4 @@ -use super::post_view::post_mview::BoxedQuery; +use super::post_view::post_view::BoxedQuery; use crate::db::{fuzzy_search, limit_and_offset, ListingType, MaybeOptional, SortType}; use diesel::{dsl::*, pg::Pg, result::Error, *}; use serde::{Deserialize, Serialize}; @@ -51,53 +51,6 @@ table! { } } -table! { - post_mview (id) { - id -> Int4, - name -> Varchar, - url -> Nullable, - body -> Nullable, - creator_id -> Int4, - community_id -> Int4, - removed -> Bool, - locked -> Bool, - published -> Timestamp, - updated -> Nullable, - deleted -> Bool, - nsfw -> Bool, - stickied -> Bool, - embed_title -> Nullable, - embed_description -> Nullable, - embed_html -> Nullable, - thumbnail_url -> Nullable, - ap_id -> Text, - local -> Bool, - banned -> Bool, - banned_from_community -> Bool, - creator_actor_id -> Text, - creator_local -> Bool, - creator_name -> Varchar, - creator_avatar -> Nullable, - community_actor_id -> Text, - community_local -> Bool, - community_name -> Varchar, - community_removed -> Bool, - community_deleted -> Bool, - community_nsfw -> Bool, - number_of_comments -> BigInt, - score -> BigInt, - upvotes -> BigInt, - downvotes -> BigInt, - hot_rank -> Int4, - newest_activity_time -> Timestamp, - user_id -> Nullable, - my_vote -> Nullable, - subscribed -> Nullable, - read -> Nullable, - saved -> Nullable, - } -} - #[derive( Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, )] @@ -166,9 +119,9 @@ pub struct PostQueryBuilder<'a> { impl<'a> PostQueryBuilder<'a> { pub fn create(conn: &'a PgConnection) -> Self { - use super::post_view::post_mview::dsl::*; + use super::post_view::post_view::dsl::*; - let query = post_mview.into_boxed(); + let query = post_view.into_boxed(); PostQueryBuilder { conn, @@ -249,7 +202,7 @@ impl<'a> PostQueryBuilder<'a> { } pub fn list(self) -> Result, Error> { - use super::post_view::post_mview::dsl::*; + use super::post_view::post_view::dsl::*; let mut query = self.query; @@ -345,10 +298,10 @@ impl PostView { from_post_id: i32, my_user_id: Option, ) -> Result { - use super::post_view::post_mview::dsl::*; + use super::post_view::post_view::dsl::*; use diesel::prelude::*; - let mut query = post_mview.into_boxed(); + let mut query = post_view.into_boxed(); query = query.filter(id.eq(from_post_id)); diff --git a/server/src/db/private_message_view.rs b/server/src/db/private_message_view.rs index 9a1df439..899a1084 100644 --- a/server/src/db/private_message_view.rs +++ b/server/src/db/private_message_view.rs @@ -26,29 +26,6 @@ table! { } } -table! { - private_message_mview (id) { - id -> Int4, - creator_id -> Int4, - recipient_id -> Int4, - content -> Text, - deleted -> Bool, - read -> Bool, - published -> Timestamp, - updated -> Nullable, - ap_id -> Text, - local -> Bool, - creator_name -> Varchar, - creator_avatar -> Nullable, - creator_actor_id -> Text, - creator_local -> Bool, - recipient_name -> Varchar, - recipient_avatar -> Nullable, - recipient_actor_id -> Text, - recipient_local -> Bool, - } -} - #[derive( Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, )] @@ -76,7 +53,7 @@ pub struct PrivateMessageView { pub struct PrivateMessageQueryBuilder<'a> { conn: &'a PgConnection, - query: super::private_message_view::private_message_mview::BoxedQuery<'a, Pg>, + query: super::private_message_view::private_message_view::BoxedQuery<'a, Pg>, for_recipient_id: i32, unread_only: bool, page: Option, @@ -85,9 +62,9 @@ pub struct PrivateMessageQueryBuilder<'a> { impl<'a> PrivateMessageQueryBuilder<'a> { pub fn create(conn: &'a PgConnection, for_recipient_id: i32) -> Self { - use super::private_message_view::private_message_mview::dsl::*; + use super::private_message_view::private_message_view::dsl::*; - let query = private_message_mview.into_boxed(); + let query = private_message_view.into_boxed(); PrivateMessageQueryBuilder { conn, @@ -115,7 +92,7 @@ impl<'a> PrivateMessageQueryBuilder<'a> { } pub fn list(self) -> Result, Error> { - use super::private_message_view::private_message_mview::dsl::*; + use super::private_message_view::private_message_view::dsl::*; let mut query = self.query.filter(deleted.eq(false)); diff --git a/server/src/db/user_mention_view.rs b/server/src/db/user_mention_view.rs index 100445b9..41ade0bb 100644 --- a/server/src/db/user_mention_view.rs +++ b/server/src/db/user_mention_view.rs @@ -39,42 +39,6 @@ table! { } } -table! { - user_mention_mview (id) { - id -> Int4, - user_mention_id -> Int4, - creator_id -> Int4, - creator_actor_id -> Text, - creator_local -> Bool, - post_id -> Int4, - parent_id -> Nullable, - content -> Text, - removed -> Bool, - read -> Bool, - published -> Timestamp, - updated -> Nullable, - deleted -> Bool, - community_id -> Int4, - community_actor_id -> Text, - community_local -> Bool, - community_name -> Varchar, - banned -> Bool, - banned_from_community -> Bool, - creator_name -> Varchar, - creator_avatar -> Nullable, - score -> BigInt, - upvotes -> BigInt, - downvotes -> BigInt, - hot_rank -> Int4, - user_id -> Nullable, - my_vote -> Nullable, - saved -> Nullable, - recipient_id -> Int4, - recipient_actor_id -> Text, - recipient_local -> Bool, - } -} - #[derive( Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, )] @@ -115,7 +79,7 @@ pub struct UserMentionView { pub struct UserMentionQueryBuilder<'a> { conn: &'a PgConnection, - query: super::user_mention_view::user_mention_mview::BoxedQuery<'a, Pg>, + query: super::user_mention_view::user_mention_view::BoxedQuery<'a, Pg>, for_user_id: i32, sort: &'a SortType, unread_only: bool, @@ -125,9 +89,9 @@ pub struct UserMentionQueryBuilder<'a> { impl<'a> UserMentionQueryBuilder<'a> { pub fn create(conn: &'a PgConnection, for_user_id: i32) -> Self { - use super::user_mention_view::user_mention_mview::dsl::*; + use super::user_mention_view::user_mention_view::dsl::*; - let query = user_mention_mview.into_boxed(); + let query = user_mention_view.into_boxed(); UserMentionQueryBuilder { conn, @@ -161,7 +125,7 @@ impl<'a> UserMentionQueryBuilder<'a> { } pub fn list(self) -> Result, Error> { - use super::user_mention_view::user_mention_mview::dsl::*; + use super::user_mention_view::user_mention_view::dsl::*; let mut query = self.query; diff --git a/server/src/db/user_view.rs b/server/src/db/user_view.rs index 57e2a4c9..e717e038 100644 --- a/server/src/db/user_view.rs +++ b/server/src/db/user_view.rs @@ -1,4 +1,4 @@ -use super::user_view::user_mview::BoxedQuery; +use super::user_view::user_view::BoxedQuery; use crate::db::{fuzzy_search, limit_and_offset, MaybeOptional, SortType}; use diesel::{dsl::*, pg::Pg, result::Error, *}; use serde::{Deserialize, Serialize}; @@ -25,28 +25,6 @@ table! { } } -table! { - user_mview (id) { - id -> Int4, - actor_id -> Text, - name -> Varchar, - avatar -> Nullable, - email -> Nullable, - matrix_user_id -> Nullable, - bio -> Nullable, - local -> Bool, - admin -> Bool, - banned -> Bool, - show_avatars -> Bool, - send_notifications_to_email -> Bool, - published -> Timestamp, - number_of_posts -> BigInt, - post_score -> BigInt, - number_of_comments -> BigInt, - comment_score -> BigInt, - } -} - #[derive( Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, )] @@ -81,9 +59,9 @@ pub struct UserQueryBuilder<'a> { impl<'a> UserQueryBuilder<'a> { pub fn create(conn: &'a PgConnection) -> Self { - use super::user_view::user_mview::dsl::*; + use super::user_view::user_view::dsl::*; - let query = user_mview.into_boxed(); + let query = user_view.into_boxed(); UserQueryBuilder { conn, @@ -100,7 +78,7 @@ impl<'a> UserQueryBuilder<'a> { } pub fn search_term>(mut self, search_term: T) -> Self { - use super::user_view::user_mview::dsl::*; + use super::user_view::user_view::dsl::*; if let Some(search_term) = search_term.get_optional() { self.query = self.query.filter(name.ilike(fuzzy_search(&search_term))); } @@ -118,7 +96,7 @@ impl<'a> UserQueryBuilder<'a> { } pub fn list(self) -> Result, Error> { - use super::user_view::user_mview::dsl::*; + use super::user_view::user_view::dsl::*; let mut query = self.query; @@ -151,17 +129,17 @@ impl<'a> UserQueryBuilder<'a> { impl UserView { pub fn read(conn: &PgConnection, from_user_id: i32) -> Result { - use super::user_view::user_mview::dsl::*; - user_mview.find(from_user_id).first::(conn) + use super::user_view::user_view::dsl::*; + user_view.find(from_user_id).first::(conn) } pub fn admins(conn: &PgConnection) -> Result, Error> { - use super::user_view::user_mview::dsl::*; - user_mview.filter(admin.eq(true)).load::(conn) + use super::user_view::user_view::dsl::*; + user_view.filter(admin.eq(true)).load::(conn) } pub fn banned(conn: &PgConnection) -> Result, Error> { - use super::user_view::user_mview::dsl::*; - user_mview.filter(banned.eq(true)).load::(conn) + use super::user_view::user_view::dsl::*; + user_view.filter(banned.eq(true)).load::(conn) } }