From 9cb24a0b1e854d9167044325320d35bfab1cd08d Mon Sep 17 00:00:00 2001 From: liquidev Date: Sat, 24 Aug 2024 12:53:52 +0200 Subject: [PATCH] remove unused imports --- crates/haku/src/render.rs | 2 +- crates/rkgk/src/api/wall.rs | 38 ++++--------------- crates/rkgk/src/login/database.rs | 2 +- crates/rkgk/src/main.rs | 2 - crates/rkgk/src/wall/auto_save.rs | 7 ++-- crates/rkgk/src/wall/chunk_images.rs | 15 -------- crates/rkgk/src/wall/chunk_iterator.rs | 22 ----------- crates/rkgk/src/wall/database.rs | 51 ++++---------------------- 8 files changed, 19 insertions(+), 120 deletions(-) diff --git a/crates/haku/src/render.rs b/crates/haku/src/render.rs index 1ba1a21..623e0da 100644 --- a/crates/haku/src/render.rs +++ b/crates/haku/src/render.rs @@ -1,6 +1,6 @@ use alloc::vec::Vec; use tiny_skia::{ - BlendMode, Color, FillRule, LineCap, Paint, Path, PathBuilder, Pixmap, Rect, Shader, + BlendMode, Color, FillRule, LineCap, Paint, Path, PathBuilder, Pixmap, Shader, Stroke as SStroke, Transform, }; diff --git a/crates/rkgk/src/api/wall.rs b/crates/rkgk/src/api/wall.rs index 0a2f5da..35004fa 100644 --- a/crates/rkgk/src/api/wall.rs +++ b/crates/rkgk/src/api/wall.rs @@ -19,10 +19,9 @@ use schema::{ use serde::{Deserialize, Serialize}; use tokio::{ select, - sync::{self, mpsc, oneshot}, - time::Instant, + sync::{mpsc, oneshot}, }; -use tracing::{error, info, instrument}; +use tracing::{error, instrument}; use crate::{ haku::{Haku, Limits}, @@ -254,8 +253,7 @@ impl SessionLoop { .name(String::from("haku render thread")) .spawn({ let wall = Arc::clone(&wall); - let chunk_images = Arc::clone(&chunk_images); - move || Self::render_thread(wall, chunk_images, limits, render_commands_rx) + move || Self::render_thread(wall, limits, render_commands_rx) }) .context("could not spawn render thread")?; @@ -415,12 +413,7 @@ impl SessionLoop { Ok(()) } - fn render_thread( - wall: Arc, - chunk_images: Arc, - limits: Limits, - mut commands: mpsc::Receiver, - ) { + fn render_thread(wall: Arc, limits: Limits, mut commands: mpsc::Receiver) { let mut haku = Haku::new(limits); let mut brush_ok = false; @@ -436,7 +429,7 @@ impl SessionLoop { for point in points { // Ignore the result. It's better if we render _something_ rather // than nothing. - _ = draw_to_chunks(&wall, &chunk_images, &haku, value, point); + _ = draw_to_chunks(&wall, &haku, value, point); } haku.reset_vm(); } @@ -467,14 +460,8 @@ fn chunks_to_modify(wall: &Wall, points: &[Vec2]) -> HashSet { chunks } -#[instrument(skip(wall, chunk_images, haku, value))] -fn draw_to_chunks( - wall: &Wall, - chunk_images: &ChunkImages, - haku: &Haku, - value: Value, - center: Vec2, -) -> eyre::Result<()> { +#[instrument(skip(wall, haku, value))] +fn draw_to_chunks(wall: &Wall, haku: &Haku, value: Value, center: Vec2) -> eyre::Result<()> { let settings = wall.settings(); let chunk_size = settings.chunk_size as f32; @@ -497,16 +484,5 @@ fn draw_to_chunks( } } - // NOTE: Maybe sending in an iterator would be more efficient? - // If there were many chunks modified, (which there probably weren't,) this could allocate - // a lot of memory. - chunk_images.mark_modified_blocking( - (top_chunk..bottom_chunk) - .flat_map(|chunk_y| { - (left_chunk..right_chunk).map(move |chunk_x| ChunkPosition::new(chunk_x, chunk_y)) - }) - .collect(), - ); - Ok(()) } diff --git a/crates/rkgk/src/login/database.rs b/crates/rkgk/src/login/database.rs index e588777..d51a097 100644 --- a/crates/rkgk/src/login/database.rs +++ b/crates/rkgk/src/login/database.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use argon2::{ - password_hash::{PasswordHasher, Salt, SaltString}, + password_hash::{PasswordHasher, SaltString}, Argon2, PasswordHash, PasswordVerifier, }; use base64::Engine; diff --git a/crates/rkgk/src/main.rs b/crates/rkgk/src/main.rs index aea8e11..b322b18 100644 --- a/crates/rkgk/src/main.rs +++ b/crates/rkgk/src/main.rs @@ -13,10 +13,8 @@ use eyre::Context; use tokio::{fs, net::TcpListener}; use tower_http::services::{ServeDir, ServeFile}; use tracing::{info, info_span}; -use tracing_subscriber::fmt::format::FmtSpan; mod api; -mod binary; mod config; mod haku; mod id; diff --git a/crates/rkgk/src/wall/auto_save.rs b/crates/rkgk/src/wall/auto_save.rs index ebda9b4..e6fba3f 100644 --- a/crates/rkgk/src/wall/auto_save.rs +++ b/crates/rkgk/src/wall/auto_save.rs @@ -1,14 +1,13 @@ -use std::{backtrace::Backtrace, collections::HashSet, sync::Arc, time::Duration}; +use std::{collections::HashSet, sync::Arc, time::Duration}; -use dashmap::DashSet; use serde::{Deserialize, Serialize}; use tokio::{ sync::mpsc, time::{interval, MissedTickBehavior}, }; -use tracing::{info, instrument}; +use tracing::instrument; -use super::{chunk_images::ChunkImages, ChunkPosition, Database, Wall}; +use super::{chunk_images::ChunkImages, ChunkPosition}; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct Settings { diff --git a/crates/rkgk/src/wall/chunk_images.rs b/crates/rkgk/src/wall/chunk_images.rs index 40f1210..de76835 100644 --- a/crates/rkgk/src/wall/chunk_images.rs +++ b/crates/rkgk/src/wall/chunk_images.rs @@ -26,10 +26,6 @@ enum Command { chunks: Vec, reply: oneshot::Sender>, }, - - MarkModified { - chunks: Vec, - }, } impl ChunkImages { @@ -69,12 +65,6 @@ impl ChunkImages { rx.await.context("failed to load chunks")? } - pub fn mark_modified_blocking(&self, chunks: Vec) { - _ = self - .commands_tx - .blocking_send(Command::MarkModified { chunks }); - } - pub fn chunk_exists(&self, position: ChunkPosition) -> bool { self.wall.has_chunk(position) || self.async_loop.chunks_in_db.contains(&position) } @@ -221,17 +211,12 @@ impl ChunkImageLoop { while let Some(command) = commands_rx.recv().await { match command { Command::Encode { chunks, reply } => { - // TODO: This should have a caching layer. tokio::spawn(Arc::clone(&self).encode(chunks, reply)); } Command::Load { chunks, reply } => { tokio::spawn(Arc::clone(&self).load(chunks, reply)); } - - Command::MarkModified { chunks } => { - // TODO: This should invalidate data from the caching layer. - } } } } diff --git a/crates/rkgk/src/wall/chunk_iterator.rs b/crates/rkgk/src/wall/chunk_iterator.rs index 9f4144e..63db6f2 100644 --- a/crates/rkgk/src/wall/chunk_iterator.rs +++ b/crates/rkgk/src/wall/chunk_iterator.rs @@ -1,5 +1,3 @@ -use std::iter::Take; - use super::ChunkPosition; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -19,26 +17,6 @@ impl ChunkIterator { bottom_right, } } - - pub fn take_next(&mut self, n: i32) -> Take { - assert!(n > 0); - - let take = (*self).take(n as usize); - - let x = self.cursor.x - self.left; - let width = self.bottom_right.x - self.left; - if width != 0 { - self.cursor.x = self.left + (x + n) % width; - self.cursor.y += n / width; - } else { - // In a width = 0 configuration, we iterate vertically. - // This is probably not the right thing to do, but we're just doing this to guard - // against malicious clients. - self.cursor.y += n; - } - - take - } } impl Iterator for ChunkIterator { diff --git a/crates/rkgk/src/wall/database.rs b/crates/rkgk/src/wall/database.rs index 56a168c..ee7a650 100644 --- a/crates/rkgk/src/wall/database.rs +++ b/crates/rkgk/src/wall/database.rs @@ -1,17 +1,10 @@ -use std::{ - convert::identity, - path::{Path, PathBuf}, - sync::Arc, -}; +use std::{convert::identity, path::PathBuf, sync::Arc}; -use chrono::Utc; use eyre::Context; use rusqlite::Connection; use tokio::sync::{mpsc, oneshot}; use tracing::{error, info, instrument}; -use crate::login::UserId; - use super::{ChunkPosition, WallId}; pub struct Settings { @@ -32,18 +25,12 @@ pub struct ChunkDataPair { } enum Command { - SetWallInfo { - created_by: UserId, - title: String, - reply: oneshot::Sender>, - }, - - WriteChunks { + Write { chunks: Vec, reply: oneshot::Sender>, }, - ReadChunks { + Read { chunks: Vec, reply: oneshot::Sender>, }, @@ -62,7 +49,7 @@ impl Database { pub async fn write_chunks(&self, chunks: Vec) -> eyre::Result<()> { let (tx, rx) = oneshot::channel(); self.command_tx - .send(Command::WriteChunks { chunks, reply: tx }) + .send(Command::Write { chunks, reply: tx }) .await .context("database is offline")?; rx.await.context("database returned an error")? @@ -74,7 +61,7 @@ impl Database { ) -> eyre::Result> { let (tx, rx) = oneshot::channel(); self.command_tx - .send(Command::ReadChunks { chunks, reply: tx }) + .send(Command::Read { chunks, reply: tx }) .await .context("database is offline")?; rx.await.context("database did not return anything") @@ -207,17 +194,6 @@ pub fn start(settings: Settings) -> eyre::Result { std::thread::Builder::new() .name(format!("database thread {}", settings.wall_id)) .spawn(move || { - let mut s_set_wall_info = db - .prepare( - r#" - INSERT OR REPLACE - INTO t_wall_info - (created_by, title) - VALUES (?, ?); - "#, - ) - .unwrap(); - let mut s_write_chunk = db .prepare( r#" @@ -250,20 +226,7 @@ pub fn start(settings: Settings) -> eyre::Result { while let Some(command) = command_rx.blocking_recv() { match command { - Command::SetWallInfo { - created_by, - title, - reply, - } => { - _ = reply.send( - s_set_wall_info - .execute((created_by.0, title)) - .map(|_| ()) - .context("failed to set wall info"), - ); - } - - Command::WriteChunks { chunks, reply } => { + Command::Write { chunks, reply } => { let mut result = Ok(()); for ChunkDataPair { position, data } in chunks { if let Err(error) = @@ -279,7 +242,7 @@ pub fn start(settings: Settings) -> eyre::Result { )); } - Command::ReadChunks { chunks, reply } => { + Command::Read { chunks, reply } => { let result = chunks .into_iter() .flat_map(|position| {