Before merging master to test out bans.

This commit is contained in:
Dessalines 2020-07-04 19:14:29 -04:00
parent 9c30c65c07
commit eae1b96155
6 changed files with 229 additions and 135 deletions

View file

@ -2,11 +2,14 @@
drop table user_fast; drop table user_fast;
drop table user_mention_fast; drop table user_mention_fast;
drop trigger refresh_user_mention on user_mention; drop trigger refresh_user_mention on user_mention;
drop table post_fast; drop view post_fast_view;
drop table community_fast; drop table post_aggregates_fast;
drop view community_fast_view;
drop table community_aggregates_fast;
drop table private_message_fast; drop table private_message_fast;
drop view reply_fast_view; drop view reply_fast_view;
drop table comment_fast; drop view comment_fast_view;
drop table comment_aggregates_fast;
-- Re-adding all the triggers, functions, and mviews -- Re-adding all the triggers, functions, and mviews

View file

@ -1,3 +1,5 @@
-- Drop the mviews -- Drop the mviews
drop view post_mview; drop view post_mview;
drop materialized view user_mview; drop materialized view user_mview;
@ -41,20 +43,15 @@ begin
insert into user_fast select * from user_view where id = NEW.id; insert into user_fast select * from user_view where id = NEW.id;
-- Refresh post_fast, cause of user info changes -- Refresh post_fast, cause of user info changes
-- TODO test this. Also is it locking? -- TODO test this (for example a banned user). Also is it locking?
delete from post_fast where creator_id = NEW.id; delete from post_aggregates_fast where creator_id = NEW.id;
insert into post_fast select * from post_view where creator_id = NEW.id; insert into post_aggregates_fast select * from post_aggregates_view where creator_id = NEW.id;
-- TODO delete from comment_aggregates_fast where creator_id = NEW.id;
-- refresh materialized view concurrently comment_aggregates_mview; -- cause of bans insert into comment_aggregates_fast select * from comment_aggregates_view where creator_id = NEW.id;
-- refresh materialized view concurrently post_aggregates_mview; -- cause of user info changes
ELSIF (TG_OP = 'INSERT') THEN ELSIF (TG_OP = 'INSERT') THEN
insert into user_fast select * from user_view where id = NEW.id; insert into user_fast select * from user_view where id = NEW.id;
-- Update all the fast views
insert into community_fast select * from community_view where user_id = NEW.id;
insert into post_fast select * from post_view where user_id = NEW.id;
insert into comment_fast select * from comment_view where user_id = NEW.id;
END IF; END IF;
return null; return null;
@ -62,17 +59,43 @@ end $$;
-- Post -- Post
create table post_fast as select * from post_view; create table post_aggregates_fast as select * from post_aggregates_view;
alter table post_fast add column fast_id serial primary key; alter table post_aggregates_fast add column fast_id serial primary key;
create index idx_post_fast_user_id on post_fast (user_id); create index idx_post_aggregates_fast_id on post_aggregates_fast (id);
create index idx_post_fast_id on post_fast (id);
-- For the hot rank resorting -- For the hot rank resorting
create index idx_post_fast_hot_rank on post_fast (hot_rank); create index idx_post_aggregates_fast_hot_rank on post_aggregates_fast (hot_rank desc);
create index idx_post_aggregates_fast_activity on post_aggregates_fast (newest_activity_time desc);
-- This ones for the common case of null fetches create view post_fast_view as
create index idx_post_fast_hot_rank_published_desc_user_null on post_fast (hot_rank desc, published desc) where user_id is null; with all_post as (
select
pa.*
from post_aggregates_fast pa
)
select
ap.*,
u.id as user_id,
coalesce(pl.score, 0) as my_vote,
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
from user_ u
cross join all_post ap
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
union all
select
ap.*,
null as user_id,
null as my_vote,
null as subscribed,
null as read,
null as saved
from all_post ap
;
drop trigger refresh_post on post; drop trigger refresh_post on post;
@ -82,6 +105,8 @@ on post
for each row for each row
execute procedure refresh_post(); execute procedure refresh_post();
-- Sample select
-- select id, name from post_fast_view where name like 'test_post' and user_id is null;
-- Sample insert -- Sample insert
-- insert into post(name, creator_id, community_id) values ('test_post', 2, 2); -- insert into post(name, creator_id, community_id) values ('test_post', 2, 2);
-- Sample delete -- Sample delete
@ -93,31 +118,56 @@ returns trigger language plpgsql
as $$ as $$
begin begin
IF (TG_OP = 'DELETE') THEN IF (TG_OP = 'DELETE') THEN
delete from post_fast where id = OLD.id; delete from post_aggregates_fast where id = OLD.id;
ELSIF (TG_OP = 'UPDATE') THEN ELSIF (TG_OP = 'UPDATE') THEN
delete from post_fast where id = OLD.id; delete from post_aggregates_fast where id = OLD.id;
insert into post_fast select * from post_view where id = NEW.id; insert into post_aggregates_fast select * from post_aggregates_view where id = NEW.id;
ELSIF (TG_OP = 'INSERT') THEN ELSIF (TG_OP = 'INSERT') THEN
insert into post_fast select * from post_view where id = NEW.id; insert into post_aggregates_fast select * from post_aggregates_view where id = NEW.id;
-- TODO Update the user fast table
-- Update that users number of posts, post score -- Update that users number of posts, post score
-- delete from user_fast where id = NEW.creator_id; delete from user_fast where id = NEW.creator_id;
-- insert into user_fast select * from user_view where id = NEW.creator_id; insert into user_fast select * from user_view where id = NEW.creator_id;
-- Update the hot rank on the post table TODO hopefully this doesn't lock it. -- Update the hot rank on the post table TODO hopefully this doesn't lock it.
update post_fast set hot_rank = hot_rank(coalesce(score , 0), published) where hot_rank > 0 ; -- TODO this might not correctly update it, using a 1 week interval
update post_aggregates_fast as paf
set hot_rank = pav.hot_rank
from post_aggregates_view as pav
where paf.id = pav.id and (pav.published > ('now'::timestamp - '1 week'::interval));
END IF; END IF;
return null; return null;
end $$; end $$;
-- Community -- Community
create table community_fast as select * from community_view; create table community_aggregates_fast as select * from community_aggregates_view;
alter table community_fast add column fast_id serial primary key; alter table community_aggregates_fast add column fast_id serial primary key;
create index idx_community_fast_id on community_fast (id); create index idx_community_aggregates_fast_id on community_aggregates_fast (id);
create index idx_community_fast_user_id on community_fast (user_id);
create view community_fast_view as
with all_community as
(
select
ca.*
from community_aggregates_fast ca
)
select
ac.*,
u.id as user_id,
(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed
from user_ u
cross join all_community ac
union all
select
ac.*,
null as user_id,
null as subscribed
from all_community ac;
drop trigger refresh_community on community; drop trigger refresh_community on community;
@ -127,6 +177,8 @@ on community
for each row for each row
execute procedure refresh_community(); execute procedure refresh_community();
-- Sample select
-- select * from community_fast_view where name like 'test_community_name' and user_id is null;
-- Sample insert -- Sample insert
-- insert into community(name, title, category_id, creator_id) values ('test_community_name', 'test_community_title', 1, 2); -- insert into community(name, title, category_id, creator_id) values ('test_community_name', 'test_community_title', 1, 2);
-- Sample delete -- Sample delete
@ -138,22 +190,22 @@ returns trigger language plpgsql
as $$ as $$
begin begin
IF (TG_OP = 'DELETE') THEN IF (TG_OP = 'DELETE') THEN
delete from community_fast where id = OLD.id; delete from community_aggregates_fast where id = OLD.id;
ELSIF (TG_OP = 'UPDATE') THEN ELSIF (TG_OP = 'UPDATE') THEN
delete from community_fast where id = OLD.id; delete from community_aggregates_fast where id = OLD.id;
insert into community_fast select * from community_view where id = NEW.id; insert into community_aggregates_fast select * from community_aggregates_view where id = NEW.id;
-- Update user view due to owner changes -- Update user view due to owner changes
delete from user_fast where id = NEW.creator_id; delete from user_fast where id = NEW.creator_id;
insert into user_fast select * from user_view where id = NEW.creator_id; insert into user_fast select * from user_view where id = NEW.creator_id;
-- Update post view due to community changes -- Update post view due to community changes
delete from post_fast where community_id = NEW.id; delete from post_aggregates_fast where community_id = NEW.id;
insert into post_fast select * from post_view where community_id = NEW.id; insert into post_aggregates_fast select * from post_aggregates_view where community_id = NEW.id;
-- TODO make sure this shows up in the users page ? -- TODO make sure this shows up in the users page ?
ELSIF (TG_OP = 'INSERT') THEN ELSIF (TG_OP = 'INSERT') THEN
insert into community_fast select * from community_view where id = NEW.id; insert into community_aggregates_fast select * from community_aggregates_view where id = NEW.id;
END IF; END IF;
return null; return null;
@ -198,14 +250,64 @@ end $$;
-- Comment -- Comment
create table comment_fast as select * from comment_view; create table comment_aggregates_fast as select * from comment_aggregates_view;
alter table comment_fast add column fast_id serial primary key; alter table comment_aggregates_fast add column fast_id serial primary key;
create index idx_comment_fast_user_id on comment_fast (user_id); create index idx_comment_aggregates_fast_id on comment_aggregates_fast (id);
create index idx_comment_fast_id on comment_fast (id);
-- This ones for the common case of null fetches create view comment_fast_view as
create index idx_comment_fast_hot_rank_published_desc_user_null on comment_fast (hot_rank desc, published desc) where user_id is null; with all_comment as
(
select
ca.*
from comment_aggregates_fast ca
)
select
ac.*,
u.id as user_id,
coalesce(cl.score, 0) as my_vote,
(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.community_id = cf.community_id) as subscribed,
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved
from user_ u
cross join all_comment ac
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
union all
select
ac.*,
null as user_id,
null as my_vote,
null as subscribed,
null as saved
from all_comment ac
;
-- Do the reply_view referencing the comment_fast_view
create view reply_fast_view as
with closereply as (
select
c2.id,
c2.creator_id as sender_id,
c.creator_id as recipient_id
from comment c
inner join comment c2 on c.id = c2.parent_id
where c2.creator_id != c.creator_id
-- Do union where post is null
union
select
c.id,
c.creator_id as sender_id,
p.creator_id as recipient_id
from comment c, post p
where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
)
select cv.*,
closereply.recipient_id
from comment_fast_view cv, closereply
where closereply.id = cv.id
;
drop trigger refresh_comment on comment; drop trigger refresh_comment on comment;
@ -215,6 +317,8 @@ on comment
for each row for each row
execute procedure refresh_comment(); execute procedure refresh_comment();
-- Sample select
-- select * from comment_fast_view where content = 'test_comment' and user_id is null;
-- Sample insert -- Sample insert
-- insert into comment(creator_id, post_id, content) values (2, 2, 'test_comment'); -- insert into comment(creator_id, post_id, content) values (2, 2, 'test_comment');
-- Sample delete -- Sample delete
@ -226,24 +330,29 @@ returns trigger language plpgsql
as $$ as $$
begin begin
IF (TG_OP = 'DELETE') THEN IF (TG_OP = 'DELETE') THEN
-- delete from comment_fast where id = OLD.id; delete from comment_aggregates_fast where id = OLD.id;
ELSIF (TG_OP = 'UPDATE') THEN ELSIF (TG_OP = 'UPDATE') THEN
-- delete from comment_fast where id = OLD.id; delete from comment_aggregates_fast where id = OLD.id;
-- insert into comment_fast select * from comment_view where id = NEW.id; insert into comment_aggregates_fast select * from comment_aggregates_view where id = NEW.id;
ELSIF (TG_OP = 'INSERT') THEN ELSIF (TG_OP = 'INSERT') THEN
insert into comment_fast select * from comment_view where id = NEW.id; insert into comment_aggregates_fast select * from comment_aggregates_view where id = NEW.id;
-- Update user view due to comment count -- Update user view due to comment count
-- delete from user_fast where id = NEW.creator_id; delete from user_fast where id = NEW.creator_id;
-- insert into user_fast select * from user_view where id = NEW.creator_id; insert into user_fast select * from user_view where id = NEW.creator_id;
-- Update post view due to comment count -- Update post view due to comment count, new comment activity time, but only on new posts
-- delete from post_fast where id = NEW.post_id; delete from post_aggregates_fast where id = NEW.post_id;
-- insert into post_fast select * from post_view where id = NEW.post_id; insert into post_aggregates_fast select * from post_aggregates_view where id = NEW.post_id;
-- Force the hot rank as zero on week-older posts
update post_aggregates_fast as paf
set hot_rank = 0
where paf.id = NEW.post_id and (paf.published < ('now'::timestamp - '1 week'::interval));
-- Update community view due to comment count -- Update community view due to comment count
-- delete from community_fast as cf using post as p where cf.id = p.community_id and p.id = NEW.post_id; delete from community_aggregates_fast as cf using post as p where cf.id = p.community_id and p.id = NEW.post_id;
-- insert into community_fast select cv.* from community_view cv, post p where cv.id = p.community_id and p.id = NEW.post_id; insert into community_aggregates_fast select cv.* from community_aggregates_view cv, post p where cv.id = p.community_id and p.id = NEW.post_id;
END IF; END IF;
@ -287,33 +396,8 @@ on user_mention
for each row for each row
execute procedure refresh_user_mention(); execute procedure refresh_user_mention();
-- The reply view, referencing the fast table
create view reply_fast_view as
with closereply as (
select
c2.id,
c2.creator_id as sender_id,
c.creator_id as recipient_id
from comment c
inner join comment c2 on c.id = c2.parent_id
where c2.creator_id != c.creator_id
-- Do union where post is null
union
select
c.id,
c.creator_id as sender_id,
p.creator_id as recipient_id
from comment c, post p
where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
)
select cv.*,
closereply.recipient_id
from comment_fast cv, closereply
where closereply.id = cv.id
;
-- post_like -- post_like
-- select id, score, my_vote from post_fast where id = 29 and user_id = 4; -- select id, score, my_vote from post_fast_view where id = 29 and user_id = 4;
-- Sample insert -- Sample insert
-- insert into post_like(user_id, post_id, score) values (4, 29, 1); -- insert into post_like(user_id, post_id, score) values (4, 29, 1);
-- Sample delete -- Sample delete
@ -326,16 +410,15 @@ create or replace function refresh_post_like()
returns trigger language plpgsql returns trigger language plpgsql
as $$ as $$
begin begin
-- TODO possibly select from post_fast to get previous scores, instead of re-fetching the views?
IF (TG_OP = 'DELETE') THEN IF (TG_OP = 'DELETE') THEN
delete from post_fast where id = OLD.post_id; delete from post_aggregates_fast where id = OLD.post_id;
insert into post_fast select * from post_view where id = OLD.post_id; insert into post_aggregates_fast select * from post_aggregates_view where id = OLD.post_id;
ELSIF (TG_OP = 'UPDATE') THEN ELSIF (TG_OP = 'UPDATE') THEN
delete from post_fast where id = NEW.post_id; delete from post_aggregates_fast where id = NEW.post_id;
insert into post_fast select * from post_view where id = NEW.post_id; insert into post_aggregates_fast select * from post_aggregates_view where id = NEW.post_id;
ELSIF (TG_OP = 'INSERT') THEN ELSIF (TG_OP = 'INSERT') THEN
delete from post_fast where id = NEW.post_id; delete from post_aggregates_fast where id = NEW.post_id;
insert into post_fast select * from post_view where id = NEW.post_id; insert into post_aggregates_fast select * from post_aggregates_view where id = NEW.post_id;
END IF; END IF;
return null; return null;
@ -348,21 +431,29 @@ on post_like
for each row for each row
execute procedure refresh_post_like(); execute procedure refresh_post_like();
-- comment_like
-- select id, score, my_vote from comment_fast_view where id = 29 and user_id = 4;
-- Sample insert
-- insert into comment_like(user_id, comment_id, post_id, score) values (4, 29, 51, 1);
-- Sample delete
-- delete from comment_like where user_id = 4 and comment_id = 29;
-- Sample update
-- update comment_like set score = -1 where user_id = 4 and comment_id = 29;
create or replace function refresh_comment_like() create or replace function refresh_comment_like()
returns trigger language plpgsql returns trigger language plpgsql
as $$ as $$
begin begin
-- TODO possibly select from comment_fast to get previous scores, instead of re-fetching the views? -- TODO possibly select from comment_fast to get previous scores, instead of re-fetching the views?
-- IF (TG_OP = 'DELETE') THEN IF (TG_OP = 'DELETE') THEN
-- delete from comment_fast where id = OLD.comment_id; delete from comment_aggregates_fast where id = OLD.comment_id;
-- insert into comment_fast select * from comment_view where id = OLD.comment_id; insert into comment_aggregates_fast select * from comment_aggregates_view where id = OLD.comment_id;
-- ELSIF (TG_OP = 'UPDATE') THEN ELSIF (TG_OP = 'UPDATE') THEN
-- delete from comment_fast where id = NEW.comment_id; delete from comment_aggregates_fast where id = NEW.comment_id;
-- insert into comment_fast select * from comment_view where id = NEW.comment_id; insert into comment_aggregates_fast select * from comment_aggregates_view where id = NEW.comment_id;
-- ELSIF (TG_OP = 'INSERT') THEN ELSIF (TG_OP = 'INSERT') THEN
-- delete from comment_fast where id = NEW.comment_id; delete from comment_aggregates_fast where id = NEW.comment_id;
-- insert into comment_fast select * from comment_view where id = NEW.comment_id; insert into comment_aggregates_fast select * from comment_aggregates_view where id = NEW.comment_id;
-- END IF; END IF;
return null; return null;
end $$; end $$;

View file

@ -39,7 +39,7 @@ table! {
} }
table! { table! {
comment_fast (id) { comment_fast_view (id) {
id -> Int4, id -> Int4,
creator_id -> Int4, creator_id -> Int4,
post_id -> Int4, post_id -> Int4,
@ -66,18 +66,18 @@ table! {
upvotes -> BigInt, upvotes -> BigInt,
downvotes -> BigInt, downvotes -> BigInt,
hot_rank -> Int4, hot_rank -> Int4,
fast_id -> Int4,
user_id -> Nullable<Int4>, user_id -> Nullable<Int4>,
my_vote -> Nullable<Int4>, my_vote -> Nullable<Int4>,
subscribed -> Nullable<Bool>, subscribed -> Nullable<Bool>,
saved -> Nullable<Bool>, saved -> Nullable<Bool>,
fast_id -> Int4,
} }
} }
#[derive( #[derive(
Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
)] )]
#[table_name = "comment_fast"] #[table_name = "comment_fast_view"]
pub struct CommentView { pub struct CommentView {
pub id: i32, pub id: i32,
pub creator_id: i32, pub creator_id: i32,
@ -105,16 +105,16 @@ pub struct CommentView {
pub upvotes: i64, pub upvotes: i64,
pub downvotes: i64, pub downvotes: i64,
pub hot_rank: i32, pub hot_rank: i32,
pub fast_id: i32,
pub user_id: Option<i32>, pub user_id: Option<i32>,
pub my_vote: Option<i32>, pub my_vote: Option<i32>,
pub subscribed: Option<bool>, pub subscribed: Option<bool>,
pub saved: Option<bool>, pub saved: Option<bool>,
pub fast_id: i32,
} }
pub struct CommentQueryBuilder<'a> { pub struct CommentQueryBuilder<'a> {
conn: &'a PgConnection, conn: &'a PgConnection,
query: super::comment_view::comment_fast::BoxedQuery<'a, Pg>, query: super::comment_view::comment_fast_view::BoxedQuery<'a, Pg>,
listing_type: ListingType, listing_type: ListingType,
sort: &'a SortType, sort: &'a SortType,
for_community_id: Option<i32>, for_community_id: Option<i32>,
@ -129,9 +129,9 @@ pub struct CommentQueryBuilder<'a> {
impl<'a> CommentQueryBuilder<'a> { impl<'a> CommentQueryBuilder<'a> {
pub fn create(conn: &'a PgConnection) -> Self { pub fn create(conn: &'a PgConnection) -> Self {
use super::comment_view::comment_fast::dsl::*; use super::comment_view::comment_fast_view::dsl::*;
let query = comment_fast.into_boxed(); let query = comment_fast_view.into_boxed();
CommentQueryBuilder { CommentQueryBuilder {
conn, conn,
@ -200,7 +200,7 @@ impl<'a> CommentQueryBuilder<'a> {
} }
pub fn list(self) -> Result<Vec<CommentView>, Error> { pub fn list(self) -> Result<Vec<CommentView>, Error> {
use super::comment_view::comment_fast::dsl::*; use super::comment_view::comment_fast_view::dsl::*;
let mut query = self.query; let mut query = self.query;
@ -272,8 +272,8 @@ impl CommentView {
from_comment_id: i32, from_comment_id: i32,
my_user_id: Option<i32>, my_user_id: Option<i32>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
use super::comment_view::comment_fast::dsl::*; use super::comment_view::comment_fast_view::dsl::*;
let mut query = comment_fast.into_boxed(); let mut query = comment_fast_view.into_boxed();
// The view lets you pass a null user_id, if you're not logged in // The view lets you pass a null user_id, if you're not logged in
if let Some(my_user_id) = my_user_id { if let Some(my_user_id) = my_user_id {
@ -319,11 +319,11 @@ table! {
upvotes -> BigInt, upvotes -> BigInt,
downvotes -> BigInt, downvotes -> BigInt,
hot_rank -> Int4, hot_rank -> Int4,
fast_id -> Int4,
user_id -> Nullable<Int4>, user_id -> Nullable<Int4>,
my_vote -> Nullable<Int4>, my_vote -> Nullable<Int4>,
subscribed -> Nullable<Bool>, subscribed -> Nullable<Bool>,
saved -> Nullable<Bool>, saved -> Nullable<Bool>,
fast_id -> Int4,
recipient_id -> Int4, recipient_id -> Int4,
} }
} }
@ -359,11 +359,11 @@ pub struct ReplyView {
pub upvotes: i64, pub upvotes: i64,
pub downvotes: i64, pub downvotes: i64,
pub hot_rank: i32, pub hot_rank: i32,
pub fast_id: i32,
pub user_id: Option<i32>, pub user_id: Option<i32>,
pub my_vote: Option<i32>, pub my_vote: Option<i32>,
pub subscribed: Option<bool>, pub subscribed: Option<bool>,
pub saved: Option<bool>, pub saved: Option<bool>,
pub fast_id: i32,
pub recipient_id: i32, pub recipient_id: i32,
} }
@ -583,6 +583,7 @@ mod tests {
score: 1, score: 1,
downvotes: 0, downvotes: 0,
hot_rank: 0, hot_rank: 0,
fast_id: 0,
upvotes: 1, upvotes: 1,
user_id: None, user_id: None,
my_vote: None, my_vote: None,
@ -594,7 +595,6 @@ mod tests {
community_local: true, community_local: true,
creator_actor_id: inserted_user.actor_id.to_owned(), creator_actor_id: inserted_user.actor_id.to_owned(),
creator_local: true, creator_local: true,
fast_id: 0,
}; };
let expected_comment_view_with_user = CommentView { let expected_comment_view_with_user = CommentView {
@ -617,6 +617,7 @@ mod tests {
score: 1, score: 1,
downvotes: 0, downvotes: 0,
hot_rank: 0, hot_rank: 0,
fast_id: 0,
upvotes: 1, upvotes: 1,
user_id: Some(inserted_user.id), user_id: Some(inserted_user.id),
my_vote: Some(1), my_vote: Some(1),
@ -628,7 +629,6 @@ mod tests {
community_local: true, community_local: true,
creator_actor_id: inserted_user.actor_id.to_owned(), creator_actor_id: inserted_user.actor_id.to_owned(),
creator_local: true, creator_local: true,
fast_id: 0,
}; };
let mut read_comment_views_no_user = CommentQueryBuilder::create(&conn) let mut read_comment_views_no_user = CommentQueryBuilder::create(&conn)

View file

@ -1,4 +1,4 @@
use super::community_view::community_fast::BoxedQuery; use super::community_view::community_fast_view::BoxedQuery;
use crate::db::{fuzzy_search, limit_and_offset, MaybeOptional, SortType}; use crate::db::{fuzzy_search, limit_and_offset, MaybeOptional, SortType};
use diesel::{pg::Pg, result::Error, *}; use diesel::{pg::Pg, result::Error, *};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -34,7 +34,7 @@ table! {
} }
table! { table! {
community_fast (id) { community_fast_view (id) {
id -> Int4, id -> Int4,
name -> Varchar, name -> Varchar,
title -> Varchar, title -> Varchar,
@ -58,9 +58,9 @@ table! {
number_of_posts -> BigInt, number_of_posts -> BigInt,
number_of_comments -> BigInt, number_of_comments -> BigInt,
hot_rank -> Int4, hot_rank -> Int4,
fast_id -> Int4,
user_id -> Nullable<Int4>, user_id -> Nullable<Int4>,
subscribed -> Nullable<Bool>, subscribed -> Nullable<Bool>,
fast_id -> Int4,
} }
} }
@ -115,7 +115,7 @@ table! {
#[derive( #[derive(
Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
)] )]
#[table_name = "community_fast"] #[table_name = "community_fast_view"]
pub struct CommunityView { pub struct CommunityView {
pub id: i32, pub id: i32,
pub name: String, pub name: String,
@ -140,9 +140,9 @@ pub struct CommunityView {
pub number_of_posts: i64, pub number_of_posts: i64,
pub number_of_comments: i64, pub number_of_comments: i64,
pub hot_rank: i32, pub hot_rank: i32,
pub fast_id: i32,
pub user_id: Option<i32>, pub user_id: Option<i32>,
pub subscribed: Option<bool>, pub subscribed: Option<bool>,
pub fast_id: i32,
} }
pub struct CommunityQueryBuilder<'a> { pub struct CommunityQueryBuilder<'a> {
@ -158,9 +158,9 @@ pub struct CommunityQueryBuilder<'a> {
impl<'a> CommunityQueryBuilder<'a> { impl<'a> CommunityQueryBuilder<'a> {
pub fn create(conn: &'a PgConnection) -> Self { pub fn create(conn: &'a PgConnection) -> Self {
use super::community_view::community_fast::dsl::*; use super::community_view::community_fast_view::dsl::*;
let query = community_fast.into_boxed(); let query = community_fast_view.into_boxed();
CommunityQueryBuilder { CommunityQueryBuilder {
conn, conn,
@ -205,7 +205,7 @@ impl<'a> CommunityQueryBuilder<'a> {
} }
pub fn list(self) -> Result<Vec<CommunityView>, Error> { pub fn list(self) -> Result<Vec<CommunityView>, Error> {
use super::community_view::community_fast::dsl::*; use super::community_view::community_fast_view::dsl::*;
let mut query = self.query; let mut query = self.query;
@ -261,9 +261,9 @@ impl CommunityView {
from_community_id: i32, from_community_id: i32,
from_user_id: Option<i32>, from_user_id: Option<i32>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
use super::community_view::community_fast::dsl::*; use super::community_view::community_fast_view::dsl::*;
let mut query = community_fast.into_boxed(); let mut query = community_fast_view.into_boxed();
query = query.filter(id.eq(from_community_id)); query = query.filter(id.eq(from_community_id));

View file

@ -1,4 +1,4 @@
use super::post_view::post_fast::BoxedQuery; use super::post_view::post_fast_view::BoxedQuery;
use crate::db::{fuzzy_search, limit_and_offset, ListingType, MaybeOptional, SortType}; use crate::db::{fuzzy_search, limit_and_offset, ListingType, MaybeOptional, SortType};
use diesel::{dsl::*, pg::Pg, result::Error, *}; use diesel::{dsl::*, pg::Pg, result::Error, *};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -52,7 +52,7 @@ table! {
} }
table! { table! {
post_fast (id) { post_fast_view (id) {
id -> Int4, id -> Int4,
name -> Varchar, name -> Varchar,
url -> Nullable<Text>, url -> Nullable<Text>,
@ -90,19 +90,19 @@ table! {
downvotes -> BigInt, downvotes -> BigInt,
hot_rank -> Int4, hot_rank -> Int4,
newest_activity_time -> Timestamp, newest_activity_time -> Timestamp,
fast_id -> Int4,
user_id -> Nullable<Int4>, user_id -> Nullable<Int4>,
my_vote -> Nullable<Int4>, my_vote -> Nullable<Int4>,
subscribed -> Nullable<Bool>, subscribed -> Nullable<Bool>,
read -> Nullable<Bool>, read -> Nullable<Bool>,
saved -> Nullable<Bool>, saved -> Nullable<Bool>,
fast_id -> Int4,
} }
} }
#[derive( #[derive(
Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
)] )]
#[table_name = "post_fast"] #[table_name = "post_fast_view"]
pub struct PostView { pub struct PostView {
pub id: i32, pub id: i32,
pub name: String, pub name: String,
@ -141,12 +141,12 @@ pub struct PostView {
pub downvotes: i64, pub downvotes: i64,
pub hot_rank: i32, pub hot_rank: i32,
pub newest_activity_time: chrono::NaiveDateTime, pub newest_activity_time: chrono::NaiveDateTime,
pub fast_id: i32,
pub user_id: Option<i32>, pub user_id: Option<i32>,
pub my_vote: Option<i32>, pub my_vote: Option<i32>,
pub subscribed: Option<bool>, pub subscribed: Option<bool>,
pub read: Option<bool>, pub read: Option<bool>,
pub saved: Option<bool>, pub saved: Option<bool>,
pub fast_id: i32,
} }
pub struct PostQueryBuilder<'a> { pub struct PostQueryBuilder<'a> {
@ -168,9 +168,9 @@ pub struct PostQueryBuilder<'a> {
impl<'a> PostQueryBuilder<'a> { impl<'a> PostQueryBuilder<'a> {
pub fn create(conn: &'a PgConnection) -> Self { pub fn create(conn: &'a PgConnection) -> Self {
use super::post_view::post_fast::dsl::*; use super::post_view::post_fast_view::dsl::*;
let query = post_fast.into_boxed(); let query = post_fast_view.into_boxed();
PostQueryBuilder { PostQueryBuilder {
conn, conn,
@ -251,7 +251,7 @@ impl<'a> PostQueryBuilder<'a> {
} }
pub fn list(self) -> Result<Vec<PostView>, Error> { pub fn list(self) -> Result<Vec<PostView>, Error> {
use super::post_view::post_fast::dsl::*; use super::post_view::post_fast_view::dsl::*;
let mut query = self.query; let mut query = self.query;
@ -347,10 +347,10 @@ impl PostView {
from_post_id: i32, from_post_id: i32,
my_user_id: Option<i32>, my_user_id: Option<i32>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
use super::post_view::post_fast::dsl::*; use super::post_view::post_fast_view::dsl::*;
use diesel::prelude::*; use diesel::prelude::*;
let mut query = post_fast.into_boxed(); let mut query = post_fast_view.into_boxed();
query = query.filter(id.eq(from_post_id)); query = query.filter(id.eq(from_post_id));
@ -520,6 +520,7 @@ mod tests {
hot_rank: read_post_listing_no_user.hot_rank, hot_rank: read_post_listing_no_user.hot_rank,
published: inserted_post.published, published: inserted_post.published,
newest_activity_time: inserted_post.published, newest_activity_time: inserted_post.published,
fast_id: read_post_listing_no_user.fast_id,
updated: None, updated: None,
subscribed: None, subscribed: None,
read: None, read: None,
@ -535,7 +536,6 @@ mod tests {
creator_local: true, creator_local: true,
community_actor_id: inserted_community.actor_id.to_owned(), community_actor_id: inserted_community.actor_id.to_owned(),
community_local: true, community_local: true,
fast_id: read_post_listing_no_user.fast_id,
}; };
let expected_post_listing_with_user = PostView { let expected_post_listing_with_user = PostView {
@ -566,6 +566,7 @@ mod tests {
hot_rank: read_post_listing_with_user.hot_rank, hot_rank: read_post_listing_with_user.hot_rank,
published: inserted_post.published, published: inserted_post.published,
newest_activity_time: inserted_post.published, newest_activity_time: inserted_post.published,
fast_id: read_post_listing_with_user.fast_id,
updated: None, updated: None,
subscribed: None, subscribed: None,
read: None, read: None,
@ -581,7 +582,6 @@ mod tests {
creator_local: true, creator_local: true,
community_actor_id: inserted_community.actor_id.to_owned(), community_actor_id: inserted_community.actor_id.to_owned(),
community_local: true, community_local: true,
fast_id: read_post_listing_with_user.fast_id,
}; };
let like_removed = PostLike::remove(&conn, &post_like_form).unwrap(); let like_removed = PostLike::remove(&conn, &post_like_form).unwrap();

2
ui/src/utils.ts vendored
View file

@ -919,7 +919,7 @@ export function postSort(
+a.removed - +b.removed || +a.removed - +b.removed ||
+a.deleted - +b.deleted || +a.deleted - +b.deleted ||
(communityType && +b.stickied - +a.stickied) || (communityType && +b.stickied - +a.stickied) ||
hotRankPost(b) - hotRankPost(a) b.hot_rank - a.hot_rank
); );
} }
} }