From faf044723302f22f9ce6827a7fa2b24dd817b0ac Mon Sep 17 00:00:00 2001 From: Timofey Martynov Date: Tue, 24 Mar 2020 02:09:51 +0300 Subject: [PATCH] Fix compilation warnings (#93) --- docs/src/api.room.update.md | 2 +- src/app/endpoint/room.rs | 2 +- src/app/endpoint/system.rs | 2 +- src/app/janus.rs | 2 +- src/backend/janus.rs | 16 --------- src/db/agent.rs | 16 ++------- src/db/agent_stream.rs | 44 ------------------------- src/db/janus_backend.rs | 14 -------- src/db/janus_rtc_stream.rs | 65 +++++-------------------------------- src/db/recording.rs | 4 --- src/db/room.rs | 44 +++---------------------- src/db/rtc.rs | 33 ------------------- src/main.rs | 1 + src/serde.rs | 1 + 14 files changed, 22 insertions(+), 224 deletions(-) diff --git a/docs/src/api.room.update.md b/docs/src/api.room.update.md index f579eab4..271bdb06 100644 --- a/docs/src/api.room.update.md +++ b/docs/src/api.room.update.md @@ -23,6 +23,6 @@ backend | String | _optional_ | The room backend. Available values: janus, -## Unicast rxesponse +## Unicast response If successful, the response payload contains an updated **Room** object. diff --git a/src/app/endpoint/room.rs b/src/app/endpoint/room.rs index 589d1472..238f9cbe 100644 --- a/src/app/endpoint/room.rs +++ b/src/app/endpoint/room.rs @@ -763,7 +763,7 @@ mod test { assert_eq!(evt.properties().kind(), "event"); assert_eq!(evt.payload().id, room.id()); - // Assert room abscence in the DB. + // Assert room absence in the DB. let conn = db.connection_pool().get().unwrap(); let query = crate::schema::room::table.find(room.id()); assert_eq!(query.execute(&conn).unwrap(), 0); diff --git a/src/app/endpoint/system.rs b/src/app/endpoint/system.rs index 7382b01f..1c7002cd 100644 --- a/src/app/endpoint/system.rs +++ b/src/app/endpoint/system.rs @@ -251,7 +251,7 @@ mod test { for rtc in rtcs.iter() { room::UpdateQuery::new(rtc.room_id().to_owned()) - .set_time(time) + .time(time) .execute(&conn) .unwrap(); } diff --git a/src/app/janus.rs b/src/app/janus.rs index ca207682..6d77a90b 100644 --- a/src/app/janus.rs +++ b/src/app/janus.rs @@ -1036,7 +1036,7 @@ pub(crate) async fn handle_event( .ok_or_else(|| format_err!("a room for rtc = '{}' is not found", &rtc_id))?; // Publish the update event if only stream object has been changed - // (if there was't any actual media stream, the object won't contain its start time) + // (if there weren't any actual media stream, the object won't contain its start time) if let Some(_) = rtc_stream.time() { let event = endpoint::rtc_stream::update_event( room.id(), diff --git a/src/backend/janus.rs b/src/backend/janus.rs index 00b7cafc..d68669d5 100644 --- a/src/backend/janus.rs +++ b/src/backend/janus.rs @@ -327,14 +327,6 @@ pub(crate) struct WebRtcUpEvent { } impl WebRtcUpEvent { - pub(crate) fn session_id(&self) -> i64 { - self.session_id - } - - pub(crate) fn sender(&self) -> i64 { - self.sender - } - pub(crate) fn opaque_id(&self) -> &str { &self.opaque_id } @@ -353,14 +345,6 @@ pub(crate) struct HangUpEvent { } impl HangUpEvent { - pub(crate) fn session_id(&self) -> i64 { - self.session_id - } - - pub(crate) fn sender(&self) -> i64 { - self.sender - } - pub(crate) fn opaque_id(&self) -> &str { &self.opaque_id } diff --git a/src/db/agent.rs b/src/db/agent.rs index cede951c..d100ab56 100644 --- a/src/db/agent.rs +++ b/src/db/agent.rs @@ -32,6 +32,7 @@ pub(crate) struct Object { status: Status, } +#[cfg(test)] impl Object { pub(crate) fn id(&self) -> Uuid { self.id @@ -96,20 +97,6 @@ impl<'a> ListQuery<'a> { } } - pub(crate) fn offset(self, offset: i64) -> Self { - Self { - offset: Some(offset), - ..self - } - } - - pub(crate) fn limit(self, limit: i64) -> Self { - Self { - limit: Some(limit), - ..self - } - } - pub(crate) fn execute(&self, conn: &PgConnection) -> Result, Error> { use diesel::prelude::*; @@ -172,6 +159,7 @@ impl<'a> InsertQuery<'a> { } } + #[cfg(test)] pub(crate) fn status(self, status: Status) -> Self { Self { status, ..self } } diff --git a/src/db/agent_stream.rs b/src/db/agent_stream.rs index 9c4bf730..9d2efd5c 100644 --- a/src/db/agent_stream.rs +++ b/src/db/agent_stream.rs @@ -1,6 +1,5 @@ use chrono::serde::ts_seconds; use chrono::{DateTime, Utc}; -use diesel::{pg::PgConnection, result::Error}; use serde_derive::{Deserialize, Serialize}; use uuid::Uuid; @@ -19,46 +18,3 @@ pub(crate) struct Object { #[serde(with = "ts_seconds")] created_at: DateTime, } - -impl Object { - pub(crate) fn id(&self) -> Uuid { - self.id - } - - pub(crate) fn sent_by(&self) -> Uuid { - self.sent_by - } - - pub(crate) fn label(&self) -> &str { - self.label.as_ref() - } -} - -//////////////////////////////////////////////////////////////////////////////// - -#[derive(Debug, Insertable)] -#[table_name = "agent_stream"] -pub(crate) struct InsertQuery<'a> { - id: Option, - sent_by: Uuid, - label: &'a str, -} - -impl<'a> InsertQuery<'a> { - pub(crate) fn new(sent_by: Uuid, label: &'a str) -> Self { - Self { - id: None, - sent_by, - label, - } - } - - pub(crate) fn execute(&self, conn: &PgConnection) -> Result { - use crate::schema::agent_stream::dsl::agent_stream; - use diesel::RunQueryDsl; - - diesel::insert_into(agent_stream) - .values(self) - .get_result(conn) - } -} diff --git a/src/db/janus_backend.rs b/src/db/janus_backend.rs index 0a964866..4d1afe95 100644 --- a/src/db/janus_backend.rs +++ b/src/db/janus_backend.rs @@ -54,20 +54,6 @@ impl<'a> ListQuery<'a> { } } - pub(crate) fn offset(self, offset: i64) -> Self { - Self { - offset: Some(offset), - ..self - } - } - - pub(crate) fn limit(self, limit: i64) -> Self { - Self { - limit: Some(limit), - ..self - } - } - pub(crate) fn execute(&self, conn: &PgConnection) -> Result, Error> { use diesel::prelude::*; diff --git a/src/db/janus_rtc_stream.rs b/src/db/janus_rtc_stream.rs index 28b646ad..cadab85a 100644 --- a/src/db/janus_rtc_stream.rs +++ b/src/db/janus_rtc_stream.rs @@ -55,6 +55,7 @@ pub(crate) struct Object { } impl Object { + #[cfg(test)] pub(crate) fn handle_id(&self) -> i64 { self.handle_id } @@ -67,10 +68,12 @@ impl Object { &self.backend_id } + #[cfg(test)] pub(crate) fn label(&self) -> &str { self.label.as_ref() } + #[cfg(test)] pub(crate) fn sent_by(&self) -> &AgentId { &self.sent_by } @@ -79,6 +82,7 @@ impl Object { self.time } + #[cfg(test)] pub(crate) fn created_at(&self) -> DateTime { self.created_at } @@ -86,15 +90,9 @@ impl Object { //////////////////////////////////////////////////////////////////////////////// -const ACTIVE_SQL: &str = r#"( - lower("janus_rtc_stream"."time") is not null - and upper("janus_rtc_stream"."time") is null -)"#; - pub(crate) struct FindQuery { id: Option, rtc_id: Option, - active: Option, } impl FindQuery { @@ -102,14 +100,6 @@ impl FindQuery { Self { id: None, rtc_id: None, - active: None, - } - } - - pub(crate) fn id(self, id: Uuid) -> Self { - Self { - id: Some(id), - ..self } } @@ -120,15 +110,7 @@ impl FindQuery { } } - pub(crate) fn active(self, active: bool) -> Self { - Self { - active: Some(active), - ..self - } - } - pub(crate) fn execute(&self, conn: &PgConnection) -> Result, Error> { - use diesel::dsl::sql; use diesel::prelude::*; let query = match (self.id, self.rtc_id) { @@ -143,18 +125,17 @@ impl FindQuery { } }; - let query = match self.active { - Some(true) => query.filter(sql(ACTIVE_SQL)), - Some(false) => query.filter(sql(&format!("not {}", ACTIVE_SQL))), - None => query, - }; - query.get_result(conn).optional() } } //////////////////////////////////////////////////////////////////////////////// +const ACTIVE_SQL: &str = r#"( + lower("janus_rtc_stream"."time") is not null + and upper("janus_rtc_stream"."time") is null +)"#; + pub(crate) struct ListQuery { room_id: Option, rtc_id: Option, @@ -183,20 +164,6 @@ impl ListQuery { } } - pub(crate) fn rtc_id(self, rtc_id: Uuid) -> Self { - Self { - rtc_id: Some(rtc_id), - ..self - } - } - - pub(crate) fn time(self, time: Time) -> Self { - Self { - time: Some(time), - ..self - } - } - pub(crate) fn active(self, active: bool) -> Self { Self { active: Some(active), @@ -204,20 +171,6 @@ impl ListQuery { } } - pub(crate) fn offset(self, offset: i64) -> Self { - Self { - offset: Some(offset), - ..self - } - } - - pub(crate) fn limit(self, limit: i64) -> Self { - Self { - limit: Some(limit), - ..self - } - } - pub(crate) fn execute(&self, conn: &PgConnection) -> Result, Error> { use diesel::prelude::*; use diesel::{dsl::sql, sql_types::Tstzrange}; diff --git a/src/db/recording.rs b/src/db/recording.rs index b2bbe1fd..665cf46c 100644 --- a/src/db/recording.rs +++ b/src/db/recording.rs @@ -44,10 +44,6 @@ pub(crate) struct Object { } impl Object { - pub(crate) fn into_tuple(self) -> (Uuid, Status, Option>, Option>) { - (self.rtc_id, self.status, self.started_at, self.segments) - } - pub(crate) fn started_at(&self) -> &Option> { &self.started_at } diff --git a/src/db/room.rs b/src/db/room.rs index 46c462e1..bdcabadf 100644 --- a/src/db/room.rs +++ b/src/db/room.rs @@ -94,10 +94,12 @@ impl Object { self.id } + #[cfg(test)] pub(crate) fn time(&self) -> Time { self.time } + #[cfg(test)] pub(crate) fn created_at(&self) -> DateTime { self.created_at } @@ -170,35 +172,6 @@ impl FindQuery { //////////////////////////////////////////////////////////////////////////////// -pub(crate) struct ListQuery { - finished: Option, -} - -impl ListQuery { - pub(crate) fn new() -> Self { - Self { finished: None } - } - - pub(crate) fn finished(self, finished: bool) -> Self { - Self { - finished: Some(finished), - ..self - } - } - - pub(crate) fn execute(&self, conn: &PgConnection) -> Result, Error> { - use diesel::{dsl::sql, prelude::*}; - - let mut q = room::table.into_boxed(); - - if let Some(true) = self.finished { - q = q.filter(sql("upper(\"room\".\"time\") < now()")); - } - - q.load(conn) - } -} - // Filtering out rooms with every recording ready using left and inner joins // and condition that recording.rtc_id is null. In diagram below room1 // and room3 will be selected (room1 - there's one recording that is not @@ -227,7 +200,6 @@ pub(crate) fn finished_without_recordings( #[derive(Debug, Insertable)] #[table_name = "room"] pub(crate) struct InsertQuery<'a> { - id: Option, time: Time, audience: &'a str, backend: RoomBackend, @@ -236,20 +208,12 @@ pub(crate) struct InsertQuery<'a> { impl<'a> InsertQuery<'a> { pub(crate) fn new(time: Time, audience: &'a str, backend: RoomBackend) -> Self { Self { - id: None, time, audience, backend, } } - pub(crate) fn id(self, id: Uuid) -> Self { - Self { - id: Some(id), - ..self - } - } - pub(crate) fn execute(&self, conn: &PgConnection) -> Result { use crate::schema::room::dsl::room; use diesel::RunQueryDsl; @@ -290,6 +254,7 @@ pub(crate) struct UpdateQuery { } impl UpdateQuery { + #[cfg(test)] pub(crate) fn new(id: Uuid) -> Self { Self { id, @@ -303,7 +268,8 @@ impl UpdateQuery { self.id } - pub(crate) fn set_time(self, time: Time) -> Self { + #[cfg(test)] + pub(crate) fn time(self, time: Time) -> Self { Self { time: Some(time), ..self diff --git a/src/db/rtc.rs b/src/db/rtc.rs index 2955735c..1156095c 100644 --- a/src/db/rtc.rs +++ b/src/db/rtc.rs @@ -35,10 +35,6 @@ impl Object { pub(crate) fn room_id(&self) -> Uuid { self.room_id } - - pub(crate) fn created_at(&self) -> DateTime { - self.created_at - } } //////////////////////////////////////////////////////////////////////////////// @@ -78,35 +74,6 @@ pub(crate) struct ListQuery { } impl ListQuery { - pub(crate) fn new() -> Self { - Self { - room_id: None, - offset: None, - limit: None, - } - } - - pub(crate) fn room_id(self, room_id: Uuid) -> Self { - Self { - room_id: Some(room_id), - ..self - } - } - - pub(crate) fn offset(self, offset: i64) -> Self { - Self { - offset: Some(offset), - ..self - } - } - - pub(crate) fn limit(self, limit: i64) -> Self { - Self { - limit: Some(limit), - ..self - } - } - pub(crate) fn execute(&self, conn: &PgConnection) -> Result, Error> { use diesel::prelude::*; diff --git a/src/main.rs b/src/main.rs index 500e09d1..885cd9e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,6 +71,7 @@ fn main() { mod app; mod backend; mod db; +#[allow(unused_imports)] mod schema; mod serde; #[cfg(test)] diff --git a/src/serde.rs b/src/serde.rs index 7f81f081..8e23578a 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -73,6 +73,7 @@ pub(crate) mod ts_seconds_option { } } + #[cfg(test)] pub fn deserialize<'de, D>(d: D) -> Result>, D::Error> where D: de::Deserializer<'de>,