···1818tools.watchexec = "latest"
1919description = "Run the server in development mode with file watching"
2020run = "mise watch --restart -e rs,gleam,toml,css,ts,json --clear=clear check"
2121+2222+[clippy_watch]
2323+tools.watchexec = "latest"
2424+run = "watchexec -c clear -restart -e rs,toml 'clear ; cargo clippy'"
+4-3
server/src/client_communication.rs
···297297 LuminaError::AuthenticationWrongPassword => {
298298 authentication_error_elog!(ev_log,"User {} {} authenticated: Incorrect credentials", email_username.color_bright_cyan(), "not".color_red());
299299 }
300300- LuminaError::AuthenticationUserNotFound => {
301301- authentication_error_elog!(ev_log,"User {} {} authenticated: User not found", email_username.color_bright_cyan(), "not".color_red());
302302- }
300300+ // LuminaError::AuthenticationUserNotFound => {
301301+ // authentication_error_elog!(ev_log,"User {} {} authenticated: User not found", email_username.color_bright_cyan(), "not".color_red());
302302+ // }
303303 _ => {
304304 authentication_error_elog!(ev_log,"User {} {} authenticated: {:?}", email_username.color_bright_cyan(), "not".color_red(), s);
305305 }
···541541 Web,
542542 // NativeApp will one day mean a native application, like a mobile app.
543543 // For now, it is nothing.
544544+ #[expect(dead_code, reason="Will be used when other clients are added.")]
544545 NativeApp,
545546}
+64-13
server/src/database.rs
···119119 .connect(postgres::tls::NoTls)
120120 .await
121121 .map_err(LuminaError::Postgres)?;
122122- let _ = tokio::spawn(conn.1);
122122+ tokio::spawn(conn.1);
123123 // Create a second connection to the database for spawning the maintain function
124124 let conn_two: (Client, Connection<Socket, NoTlsStream>) = pg_config
125125 .connect(postgres::tls::NoTls)
126126 .await
127127 .map_err(LuminaError::Postgres)?;
128128- let _ = tokio::spawn(conn_two.1);
128128+ tokio::spawn(conn_two.1);
129129 {
130130- let _ = conn
130130+ conn
131131 .0
132132 .batch_execute(include_str!("../../SQL/create_pg.sql"))
133133 .await
···162162 let conn_clone = conn_two.0;
163163 let pg_config_clone = pg_config.clone();
164164 let redis_pool_clone = redis_pool.clone();
165165- let _ = tokio::spawn(async move {
165165+ tokio::spawn(async move {
166166 maintain(DbConn::PgsqlConnection(
167167 (conn_clone, pg_config_clone),
168168 redis_pool_clone,
···175175176176/// This enum contains the postgres and redis connection and pool respectively. It used to have more variants before, and maybe it will once again.
177177#[derive()]
178178-pub(crate) enum DbConn {
178178+pub enum DbConn {
179179 // The config is also shared, so that for example the logger can set up its own connection, use this sparingly.
180180 /// The main database is a Postgres database in this variant.
181181 PgsqlConnection((Client, postgres::Config), Pool<redis::Client>),
182182}
183183184184-impl DbConn {
184184+pub(crate) trait DatabaseConnections {
185185 /// Get a reference to the redis pool
186186 /// This is useful for functions that need to access redis but not the main database
187187 /// such as timeline cache management
188188- /// This returns a clone of the pool, so it is cheap to call
189189- pub(crate) fn get_redis_pool(&self) -> Pool<redis::Client> {
190190- match self {
191191- DbConn::PgsqlConnection((_, _), redis_pool) => redis_pool.clone(),
192192- }
193193- }
188188+ /// This returns a clone of the pool without recreating it entirely, so it is cheap to call
189189+ fn get_redis_pool(&self) -> Pool<redis::Client>;
190190+191191+ /// Recreate the database connection.
192192+ async fn recreate(&self) -> Result<Self, LuminaError>
193193+ where
194194+ Self: Sized;
195195+}
194196197197+impl DatabaseConnections for DbConn {
195198 /// Recreate the database connection.
196199 /// This clones the pool on sqlite and for redis, and creates a new connection on postgres.
197197- pub(crate) async fn recreate(&self) -> Result<Self, LuminaError> {
200200+ async fn recreate(&self) -> Result<Self, LuminaError> {
198201 match self {
199202 DbConn::PgsqlConnection((_, config), redis_pool) => {
200203 let c = config
···206209207210 Ok(DbConn::PgsqlConnection((c, config.to_owned()), r))
208211 }
212212+ }
213213+ }
214214+215215+ fn get_redis_pool(&self) -> Pool<redis::Client> {
216216+ match self {
217217+ DbConn::PgsqlConnection((_, _), redis_pool) => redis_pool.clone(),
218218+ }
219219+ }
220220+}
221221+222222+impl DatabaseConnections for PgConn {
223223+ fn get_redis_pool(&self) -> Pool<redis::Client> {
224224+ self.redis_pool.clone()
225225+ }
226226+227227+ async fn recreate(&self) -> Result<Self, LuminaError> {
228228+ let postgres = self
229229+ .postgres_config
230230+ .connect(tokio_postgres::tls::NoTls)
231231+ .await
232232+ .map_err(LuminaError::Postgres)?
233233+ .0;
234234+ let postgres_config = self.postgres_config.to_owned();
235235+ let redis_pool = self.redis_pool.clone();
236236+ Ok(PgConn {
237237+ postgres,
238238+ postgres_config,
239239+ redis_pool,
240240+ })
241241+ }
242242+}
243243+/// Simplified type only accounting for the Postgres struct, since the enum adds some future flexibility, but also a lot of overhead.
244244+/// If all goes well, this PgConn type will have replaced DbConn entirely after a few iterations of improvement over the years.
245245+pub struct PgConn {
246246+ pub(crate) postgres: Client,
247247+ postgres_config: postgres::Config,
248248+ pub(crate) redis_pool: Pool<redis::Client>,
249249+}
250250+251251+impl DbConn {
252252+ /// Converts/unwraps the generic DbConn type to it's more concrete PgConn counterpart.
253253+ pub(crate) fn to_pgconn(db: Self) -> PgConn {
254254+ match db {
255255+ Self::PgsqlConnection((a, b), c) => PgConn {
256256+ postgres: a,
257257+ postgres_config: b,
258258+ redis_pool: c,
259259+ },
209260 }
210261 }
211262}