]> Untitled Git - lemmy.git/commitdiff
Fix issue with adding multiple instances of chatserver.
authorDessalines <tyhou13@gmx.com>
Thu, 16 Jan 2020 03:01:14 +0000 (22:01 -0500)
committerDessalines <tyhou13@gmx.com>
Thu, 16 Jan 2020 03:01:14 +0000 (22:01 -0500)
server/.rustfmt.toml
server/src/main.rs
server/src/routes/websocket.rs
server/src/schema.rs
server/src/websocket/server.rs

index b196eaa2dc024b48c0198357d6d61bf12a6e9c06..b1fce9c9a5718f2922ca5593fdd64b58d1920da8 100644 (file)
@@ -1 +1,2 @@
 tab_spaces = 2
+edition="2018"
index 3ac07233e5c6566f0d1e7f25cf300b682137b0d9..636182aa45c5b1a7a86348fe285a7b72ced9b064 100644 (file)
@@ -2,11 +2,13 @@ extern crate lemmy_server;
 #[macro_use]
 extern crate diesel_migrations;
 
+use actix::prelude::*;
 use actix_web::*;
 use diesel::r2d2::{ConnectionManager, Pool};
 use diesel::PgConnection;
 use lemmy_server::routes::{federation, feeds, index, nodeinfo, webfinger, websocket};
 use lemmy_server::settings::Settings;
+use lemmy_server::websocket::server::*;
 use std::io;
 
 embed_migrations!();
@@ -27,6 +29,9 @@ async fn main() -> io::Result<()> {
   let conn = pool.get().unwrap();
   embedded_migrations::run(&conn).unwrap();
 
+  // Set up websocket server
+  let server = ChatServer::startup(pool.clone()).start();
+
   println!(
     "Starting http server at {}:{}",
     settings.bind, settings.port
@@ -37,6 +42,7 @@ async fn main() -> io::Result<()> {
     App::new()
       .wrap(middleware::Logger::default())
       .data(pool.clone())
+      .data(server.clone())
       // The routes
       .configure(federation::config)
       .configure(feeds::config)
index f5e24e48cfb707045f1cca91949af3783913734f..a68b2bcded554b8161c51177f9cdf97404fcda7b 100644 (file)
@@ -1,27 +1,12 @@
 use crate::websocket::server::*;
-use crate::Settings;
 use actix::prelude::*;
 use actix_web::web;
 use actix_web::*;
 use actix_web_actors::ws;
-use diesel::r2d2::{ConnectionManager, Pool};
-use diesel::PgConnection;
 use std::time::{Duration, Instant};
 
 pub fn config(cfg: &mut web::ServiceConfig) {
-  // TODO couldn't figure out how to get this method to recieve the other pool
-  let settings = Settings::get();
-  let manager = ConnectionManager::<PgConnection>::new(&settings.get_database_url());
-  let pool = Pool::builder()
-    .max_size(settings.database.pool_size)
-    .build(manager)
-    .unwrap_or_else(|_| panic!("Error connecting to {}", settings.get_database_url()));
-
-  // Start chat server actor in separate thread
-  let server = ChatServer::startup(pool).start();
-  cfg
-    .data(server)
-    .service(web::resource("/api/v1/ws").to(chat_route));
+  cfg.service(web::resource("/api/v1/ws").to(chat_route));
 }
 
 /// How often heartbeat pings are sent
@@ -38,8 +23,7 @@ async fn chat_route(
   // TODO not sure if the blocking should be here or not
   ws::start(
     WSSession {
-      // db: db.get_ref().clone(),
-      cs_addr: chat_server.get_ref().clone(),
+      cs_addr: chat_server.get_ref().to_owned(),
       id: 0,
       hb: Instant::now(),
       ip: req
index bba39c305b393dbbe28fcd19d58509cc6f0b761d..61957067c51b2a071d69dad9cc320dc3221e9a10 100644 (file)
@@ -335,30 +335,30 @@ joinable!(user_mention -> comment (comment_id));
 joinable!(user_mention -> user_ (recipient_id));
 
 allow_tables_to_appear_in_same_query!(
-    category,
-    comment,
-    comment_like,
-    comment_saved,
-    community,
-    community_follower,
-    community_moderator,
-    community_user_ban,
-    mod_add,
-    mod_add_community,
-    mod_ban,
-    mod_ban_from_community,
-    mod_lock_post,
-    mod_remove_comment,
-    mod_remove_community,
-    mod_remove_post,
-    mod_sticky_post,
-    password_reset_request,
-    post,
-    post_like,
-    post_read,
-    post_saved,
-    site,
-    user_,
-    user_ban,
-    user_mention,
+  category,
+  comment,
+  comment_like,
+  comment_saved,
+  community,
+  community_follower,
+  community_moderator,
+  community_user_ban,
+  mod_add,
+  mod_add_community,
+  mod_ban,
+  mod_ban_from_community,
+  mod_lock_post,
+  mod_remove_comment,
+  mod_remove_community,
+  mod_remove_post,
+  mod_sticky_post,
+  password_reset_request,
+  post,
+  post_like,
+  post_read,
+  post_saved,
+  site,
+  user_,
+  user_ban,
+  user_mention,
 );
index 006169dfb9e47ad6c0ea4f926a7a78058cc9c58d..957c5f643296e64c8084fee161485e9dd5ce1153 100644 (file)
@@ -87,21 +87,6 @@ pub struct ChatServer {
   db: Pool<ConnectionManager<PgConnection>>,
 }
 
-// impl Default for ChatServer {
-//   fn default(nah: String) -> ChatServer {
-//     // default room
-//     let rooms = HashMap::new();
-
-//     ChatServer {
-//       sessions: HashMap::new(),
-//       rate_limits: HashMap::new(),
-//       rooms,
-//       rng: rand::thread_rng(),
-//       nah: nah,
-//     }
-//   }
-// }
-
 impl ChatServer {
   pub fn startup(db: Pool<ConnectionManager<PgConnection>>) -> ChatServer {
     // default room