summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDessalines <happydooby@gmail.com>2019-05-01 22:26:31 -0700
committerDessalines <happydooby@gmail.com>2019-05-01 22:26:31 -0700
commitb304b482eafd8ab87bd9fb8c263773a038ea1e6f (patch)
tree4aaee50876fd32c1f01fd4c5b05c57cd6aa096be /server
parentb2d8bf304eff145999ed38956e88978a6e1b44fb (diff)
Reworking some UI. Adding proper trending communities with hot rank.
- Breaking out subscribed and all into radios. Fixes #142
Diffstat (limited to 'server')
-rw-r--r--server/migrations/2019-05-02-051656_community_view_hot_rank/down.sql28
-rw-r--r--server/migrations/2019-05-02-051656_community_view_hot_rank/up.sql29
-rw-r--r--server/src/actions/community_view.rs3
-rw-r--r--server/src/websocket_server/server.rs3
4 files changed, 62 insertions, 1 deletions
diff --git a/server/migrations/2019-05-02-051656_community_view_hot_rank/down.sql b/server/migrations/2019-05-02-051656_community_view_hot_rank/down.sql
new file mode 100644
index 00000000..0f3a58a8
--- /dev/null
+++ b/server/migrations/2019-05-02-051656_community_view_hot_rank/down.sql
@@ -0,0 +1,28 @@
+drop view community_view;
+create view community_view as
+with all_community as
+(
+ select *,
+ (select name from user_ u where c.creator_id = u.id) as creator_name,
+ (select name from category ct where c.category_id = ct.id) as category_name,
+ (select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers,
+ (select count(*) from post p where p.community_id = c.id) as number_of_posts,
+ (select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments
+ from community c
+)
+
+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
+;
diff --git a/server/migrations/2019-05-02-051656_community_view_hot_rank/up.sql b/server/migrations/2019-05-02-051656_community_view_hot_rank/up.sql
new file mode 100644
index 00000000..e7e75366
--- /dev/null
+++ b/server/migrations/2019-05-02-051656_community_view_hot_rank/up.sql
@@ -0,0 +1,29 @@
+drop view community_view;
+create view community_view as
+with all_community as
+(
+ select *,
+ (select name from user_ u where c.creator_id = u.id) as creator_name,
+ (select name from category ct where c.category_id = ct.id) as category_name,
+ (select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers,
+ (select count(*) from post p where p.community_id = c.id) as number_of_posts,
+ (select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments,
+ hot_rank((select count(*) from community_follower cf where cf.community_id = c.id), c.published) as hot_rank
+ from community c
+)
+
+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
+;
diff --git a/server/src/actions/community_view.rs b/server/src/actions/community_view.rs
index a52897ff..9a162746 100644
--- a/server/src/actions/community_view.rs
+++ b/server/src/actions/community_view.rs
@@ -21,6 +21,7 @@ table! {
number_of_subscribers -> BigInt,
number_of_posts -> BigInt,
number_of_comments -> BigInt,
+ hot_rank -> Int4,
user_id -> Nullable<Int4>,
subscribed -> Nullable<Bool>,
}
@@ -92,6 +93,7 @@ pub struct CommunityView {
pub number_of_subscribers: i64,
pub number_of_posts: i64,
pub number_of_comments: i64,
+ pub hot_rank: i32,
pub user_id: Option<i32>,
pub subscribed: Option<bool>,
}
@@ -127,6 +129,7 @@ impl CommunityView {
// The view lets you pass a null user_id, if you're not logged in
match sort {
+ SortType::Hot => query = query.order_by(hot_rank.desc()).filter(user_id.is_null()),
SortType::New => query = query.order_by(published.desc()).filter(user_id.is_null()),
SortType::TopAll => {
match from_user_id {
diff --git a/server/src/websocket_server/server.rs b/server/src/websocket_server/server.rs
index b2416951..aaeae132 100644
--- a/server/src/websocket_server/server.rs
+++ b/server/src/websocket_server/server.rs
@@ -573,6 +573,7 @@ impl ChatServer {
fn check_rate_limit_full(&mut self, addr: usize, rate: i32, per: i32) -> Result<(), Error> {
if let Some(info) = self.sessions.get(&addr) {
if let Some(rate_limit) = self.rate_limits.get_mut(&info.ip) {
+ // The initial value
if rate_limit.allowance == -2f64 {
rate_limit.allowance = rate as f64;
};
@@ -625,7 +626,7 @@ impl Handler<Connect> for ChatServer {
// register session with random id
let id = self.rng.gen::<usize>();
- println!("{} Joined", &msg.ip);
+ println!("{} joined", &msg.ip);
self.sessions.insert(id, SessionInfo {
addr: msg.addr,