Implement get_voice_channels procedure server-side #29
Labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
puregarlic/microclimate!29
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "issue/21"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Some things of note:
sqlx, which check SQL queries against the DB at compile time. Ergo--no DB to check against, no successful compilation. You can solve this conundrum by usingsqlx's CLI to execute migrations. Check the README for details.createpermissions. I figure it's better to have a "join-and-create" workflow.LIVEKIT_URLneeds to behttps://instead ofwss://. This should only affect @tepichord. @seb get in touch with me to get some working credentials you can try.WIP: Implement get_voice_channels procedure server-sideto Implement get_voice_channels procedure server-sideGood PR. I wrote some Rustisms below if you feel like implementing any of them. Whatever you decide on those, this is good to merge.
@ -0,0 +1,4 @@CREATE TABLE IF NOT EXISTS channels (id VARCHAR(21) PRIMARY KEY NOT NULL,Regarding the
idfield,Per the SQLite datatypes documentation:
Given that VARCHAR(21) seemingly doesn't actually enforce a length constraint, I see two options:
CHECK(LENGTH(id) <= 21))There's also STRICT tables. I see no indication that the variable length constraint situation improves if you make this a STRICT table, but I am in favor of doing it anyways because jesus christ.
I changed the column type to
TEXTand also enabled STRICT for the table.@ -12,0 +13,4 @@simple_logger::init()?;let database_url =std::env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite:data.db?mode=rwc".to_string());std::env::var
@ -87,0 +117,4 @@let mut rows = sqlx::query_as!(ChannelRow, "SELECT * FROM channels").fetch(&self.db);let mut channels: Vec<Channel> = Vec::new();loop {In my opinion, iterators are usually a cleaner way than iteration statements to build vectors.
sqlx::query::Query::fetch returns a Stream, which you can use like an Iterator. Something like the following with the map_ok crate?
I didn't try to compile this, but that's my initial idea. Even if the actual implementation you'd need here ends up more verbose, I've found that this iterator-oriented/functional programming pattern tends to have much less nesting than iterative code with match statements. I find the former style easier to read, but ymmv
@ -87,0 +155,4 @@})}}Err(err) => {You can reduce the number of nested blocks here by simplifying the error handling with map_err and throwing with
?prior to looping.Something like:
eliminates the outer match statement and some of the inner error handling if you do it outside the for loop. I'm also favorable to using iteration/chaining inside the loop instead of doing nested for loops. If we do that, and we use std::iter::Extend then the whole room list iteration and the remaining match statement could simplify to something like:
Personally, I find this easier to read. I didn't try to compile it though lol
One more thing --
channels.iter_mut().find(|c| c.id == room.name)might be nicer to express as a HashMap indexed by room id. Incidentally, it also speeds up the operation considerably, as currently looking for a channel given a room id is O(N²) complexity (channels x rooms). Practically, we will probably never have enough channels or rooms for that to matter. I hope.usestatements d51eb00727GetVoiceChannelson the server #21