]> Untitled Git - lemmy.git/commitdiff
Remove mat views, no fast tables or caching added yet.
authorDessalines <tyhou13@gmx.com>
Tue, 30 Jun 2020 00:02:38 +0000 (20:02 -0400)
committerDessalines <tyhou13@gmx.com>
Tue, 30 Jun 2020 00:02:38 +0000 (20:02 -0400)
server/migrations/2020-06-29-222617_remove_mat_views/down.sql [new file with mode: 0644]
server/migrations/2020-06-29-222617_remove_mat_views/up.sql [new file with mode: 0644]
server/src/db/comment_view.rs
server/src/db/community_view.rs
server/src/db/post_view.rs
server/src/db/private_message_view.rs
server/src/db/user_mention_view.rs
server/src/db/user_view.rs

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 (file)
index 0000000..7c49086
--- /dev/null
@@ -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 (file)
index 0000000..eb0fb93
--- /dev/null
@@ -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;
index a37cdbcd622fcc2288b129c3560b5b9fc0e1acee..f96d9534dbc2ef6b5734e5258bff06250137bed8 100644 (file)
@@ -38,41 +38,6 @@ table! {
   }
 }
 
-table! {
-  comment_mview (id) {
-    id -> Int4,
-    creator_id -> Int4,
-    post_id -> Int4,
-    parent_id -> Nullable<Int4>,
-    content -> Text,
-    removed -> Bool,
-    read -> Bool,
-    published -> Timestamp,
-    updated -> Nullable<Timestamp>,
-    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<Text>,
-    score -> BigInt,
-    upvotes -> BigInt,
-    downvotes -> BigInt,
-    hot_rank -> Int4,
-    user_id -> Nullable<Int4>,
-    my_vote -> Nullable<Int4>,
-    subscribed -> Nullable<Bool>,
-    saved -> Nullable<Bool>,
-  }
-}
-
 #[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<i32>,
@@ -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<Vec<CommentView>, 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<i32>,
   ) -> Result<Self, Error> {
-    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 {
index ea7b2a7cadfa51950221307b63c188befa6d541c..606ec13ce0336dd4eeab7aac9ae067542e7cd83c 100644 (file)
@@ -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<Text>,
-    category_id -> Int4,
-    creator_id -> Int4,
-    removed -> Bool,
-    published -> Timestamp,
-    updated -> Nullable<Timestamp>,
-    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<Text>,
-    category_name -> Varchar,
-    number_of_subscribers -> BigInt,
-    number_of_posts -> BigInt,
-    number_of_comments -> BigInt,
-    hot_rank -> Int4,
-    user_id -> Nullable<Int4>,
-    subscribed -> Nullable<Bool>,
-  }
-}
-
 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<Vec<CommunityView>, 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<i32>,
   ) -> Result<Self, Error> {
-    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));
 
index fbbf658d35c9589016bb0ba6b3ed207d5ab9b7de..6865402fb7350d5363f359f490d9d1d95860b0ea 100644 (file)
@@ -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<Text>,
-    body -> Nullable<Text>,
-    creator_id -> Int4,
-    community_id -> Int4,
-    removed -> Bool,
-    locked -> Bool,
-    published -> Timestamp,
-    updated -> Nullable<Timestamp>,
-    deleted -> Bool,
-    nsfw -> Bool,
-    stickied -> Bool,
-    embed_title -> Nullable<Text>,
-    embed_description -> Nullable<Text>,
-    embed_html -> Nullable<Text>,
-    thumbnail_url -> Nullable<Text>,
-    ap_id -> Text,
-    local -> Bool,
-    banned -> Bool,
-    banned_from_community -> Bool,
-    creator_actor_id -> Text,
-    creator_local -> Bool,
-    creator_name -> Varchar,
-    creator_avatar -> Nullable<Text>,
-    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<Int4>,
-    my_vote -> Nullable<Int4>,
-    subscribed -> Nullable<Bool>,
-    read -> Nullable<Bool>,
-    saved -> Nullable<Bool>,
-  }
-}
-
 #[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<Vec<PostView>, 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<i32>,
   ) -> Result<Self, Error> {
-    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));
 
index 9a1df43972ee62f5ee07ee728b592343ce5db982..899a1084d81a824c230169c0f9da7f2cf8d783cf 100644 (file)
@@ -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<Timestamp>,
-    ap_id -> Text,
-    local -> Bool,
-    creator_name -> Varchar,
-    creator_avatar -> Nullable<Text>,
-    creator_actor_id -> Text,
-    creator_local -> Bool,
-    recipient_name -> Varchar,
-    recipient_avatar -> Nullable<Text>,
-    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<i64>,
@@ -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<Vec<PrivateMessageView>, 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));
 
index 100445b9938371aab7c08ffff4857ba7ace7be29..41ade0bb659223648a04b91589a0c82be3d35d09 100644 (file)
@@ -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<Int4>,
-    content -> Text,
-    removed -> Bool,
-    read -> Bool,
-    published -> Timestamp,
-    updated -> Nullable<Timestamp>,
-    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<Text>,
-    score -> BigInt,
-    upvotes -> BigInt,
-    downvotes -> BigInt,
-    hot_rank -> Int4,
-    user_id -> Nullable<Int4>,
-    my_vote -> Nullable<Int4>,
-    saved -> Nullable<Bool>,
-    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<Vec<UserMentionView>, Error> {
-    use super::user_mention_view::user_mention_mview::dsl::*;
+    use super::user_mention_view::user_mention_view::dsl::*;
 
     let mut query = self.query;
 
index 57e2a4c9c2524c5b9a8b4b6550c7b1105e42db5a..e717e0387d4b4f79c0efc94b523a0c86619e24c7 100644 (file)
@@ -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<Text>,
-    email -> Nullable<Text>,
-    matrix_user_id -> Nullable<Text>,
-    bio -> Nullable<Text>,
-    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<T: MaybeOptional<String>>(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<Vec<UserView>, 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<Self, Error> {
-    use super::user_view::user_mview::dsl::*;
-    user_mview.find(from_user_id).first::<Self>(conn)
+    use super::user_view::user_view::dsl::*;
+    user_view.find(from_user_id).first::<Self>(conn)
   }
 
   pub fn admins(conn: &PgConnection) -> Result<Vec<Self>, Error> {
-    use super::user_view::user_mview::dsl::*;
-    user_mview.filter(admin.eq(true)).load::<Self>(conn)
+    use super::user_view::user_view::dsl::*;
+    user_view.filter(admin.eq(true)).load::<Self>(conn)
   }
 
   pub fn banned(conn: &PgConnection) -> Result<Vec<Self>, Error> {
-    use super::user_view::user_mview::dsl::*;
-    user_mview.filter(banned.eq(true)).load::<Self>(conn)
+    use super::user_view::user_view::dsl::*;
+    user_view.filter(banned.eq(true)).load::<Self>(conn)
   }
 }