this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: fmt

+99 -43
+1 -1
mise/tasks/check.toml
··· 42 42 [test-watch] 43 43 tools.watchexec = "latest" 44 44 description = "Run the server in development mode with file watching" 45 - run = "mise watch --restart -e rs,gleam,toml,css,ts,json --clear=clear test" 45 + run = "mise watch --restart -e rs,gleam,toml,css,ts,json --clear=clear test"
+40 -24
server/src/database.rs
··· 24 24 use crate::helpers::events::EventLogger; 25 25 use crate::timeline; 26 26 use crate::{info_elog, success_elog, warn_elog}; 27 - use cynthia_con::{CynthiaColors, CynthiaStyles}; 28 27 use bb8::Pool; 29 28 use bb8_postgres::PostgresConnectionManager; 30 29 use bb8_redis::RedisConnectionManager; 30 + use cynthia_con::{CynthiaColors, CynthiaStyles}; 31 + use std::time::Duration; 31 32 use tokio_postgres as postgres; 32 33 use tokio_postgres::NoTls; 33 - use std::time::Duration; 34 34 35 35 pub(crate) async fn setup() -> Result<PgConn, LuminaError> { 36 36 let ev_log = EventLogger::new(&None); ··· 44 44 .max_size(50) 45 45 .connection_timeout(Duration::from_secs(5)) 46 46 .idle_timeout(Some(Duration::from_secs(300))) 47 - .build(manager).await?; 47 + .build(manager) 48 + .await?; 48 49 success_elog!( 49 50 ev_log, 50 51 "Redis connection to {} created successfully.", ··· 129 130 .await 130 131 .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 131 132 { 132 - let pg_conn = pg_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 133 + let pg_conn = pg_pool 134 + .get() 135 + .await 136 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 133 137 pg_conn 134 138 .batch_execute(include_str!("../../SQL/create_pg.sql")) 135 139 .await 136 140 .map_err(LuminaError::Postgres)?; 137 141 138 142 // Populate bloom filters 139 - let mut redis_conn = redis_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 143 + let mut redis_conn = redis_pool 144 + .get() 145 + .await 146 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 140 147 let email_key = "bloom:email"; 141 148 let username_key = "bloom:username"; 142 149 ··· 182 189 #[derive()] 183 190 pub enum DbConn { 184 191 /// The main database is a Postgres database in this variant. 185 - PgsqlConnection(Pool<PostgresConnectionManager<NoTls>>, Pool<RedisConnectionManager>), 192 + PgsqlConnection( 193 + Pool<PostgresConnectionManager<NoTls>>, 194 + Pool<RedisConnectionManager>, 195 + ), 186 196 } 187 197 188 198 pub(crate) trait DatabaseConnections { ··· 205 215 impl DatabaseConnections for DbConn { 206 216 /// Recreate the database connection. 207 217 /// This clones the pools - bb8 pools are cheap to clone as they share the underlying connections. 208 - // This function converts a generic DbConn to the more concrete PgConn type. 209 - async fn recreate(&self) -> PgConn { 218 + // This function converts a generic DbConn to the more concrete PgConn type. 219 + async fn recreate(&self) -> PgConn { 210 220 PgConn { 211 221 postgres_pool: self.get_postgres_pool(), 212 222 redis_pool: self.get_redis_pool(), ··· 225 235 } 226 236 } 227 237 228 - 229 238 impl DatabaseConnections for PgConn { 230 239 fn get_redis_pool(&self) -> Pool<RedisConnectionManager> { 231 240 self.redis_pool.clone() 232 241 } 233 242 234 - 235 243 fn get_postgres_pool(&self) -> Pool<PostgresConnectionManager<NoTls>> { 236 244 self.postgres_pool.clone() 237 245 } 238 246 239 - async fn recreate(&self) -> PgConn 240 - where 241 - Self: Sized { 247 + async fn recreate(&self) -> PgConn 248 + where 249 + Self: Sized, 250 + { 242 251 self.clone() 243 252 } 244 253 } ··· 264 273 } 265 274 } 266 275 } 267 - 268 276 269 277 // This function will be used to maintain the database, such as deleting old sessions 270 278 // and managing timeline caches ··· 304 312 } 305 313 306 314 // Clean up expired timeline cache entries 307 - async fn cleanup_timeline_caches(redis_conn: &mut bb8::PooledConnection<'_, RedisConnectionManager>) -> Result<(), LuminaError> { 315 + async fn cleanup_timeline_caches( 316 + redis_conn: &mut bb8::PooledConnection<'_, RedisConnectionManager>, 317 + ) -> Result<(), LuminaError> { 308 318 let pattern = "timeline_cache:*"; 309 319 let mut cursor = 0; 310 320 ··· 373 383 // First run, don't invalidate anything 374 384 let _: () = redis::cmd("SET") 375 385 .arg("timeline_cache_last_check") 376 - .arg(time::OffsetDateTime::now_utc() 377 - .format(&time::format_description::well_known::Rfc3339) 378 - .unwrap()) 386 + .arg( 387 + time::OffsetDateTime::now_utc() 388 + .format(&time::format_description::well_known::Rfc3339) 389 + .unwrap(), 390 + ) 379 391 .query_async(&mut **redis_conn) 380 392 .await 381 393 .map_err(LuminaError::Redis)?; ··· 392 404 // Update last check timestamp 393 405 let _: () = redis::cmd("SET") 394 406 .arg("timeline_cache_last_check") 395 - .arg(time::OffsetDateTime::now_utc() 396 - .format(&time::format_description::well_known::Rfc3339) 397 - .unwrap()) 407 + .arg( 408 + time::OffsetDateTime::now_utc() 409 + .format(&time::format_description::well_known::Rfc3339) 410 + .unwrap(), 411 + ) 398 412 .query_async(&mut **redis_conn) 399 413 .await 400 414 .map_err(LuminaError::Redis)?; ··· 403 417 // If query fails, just update timestamp to avoid repeated failures 404 418 let _: () = redis::cmd("SET") 405 419 .arg("timeline_cache_last_check") 406 - .arg(time::OffsetDateTime::now_utc() 407 - .format(&time::format_description::well_known::Rfc3339) 408 - .unwrap()) 420 + .arg( 421 + time::OffsetDateTime::now_utc() 422 + .format(&time::format_description::well_known::Rfc3339) 423 + .unwrap(), 424 + ) 409 425 .query_async(&mut **redis_conn) 410 426 .await 411 427 .map_err(LuminaError::Redis)?;
+1 -1
server/src/errors.rs
··· 56 56 fn from(err: redis::RedisError) -> Self { 57 57 LuminaError::Redis(err) 58 58 } 59 - } 59 + }
+1 -1
server/src/helpers/events.rs
··· 24 24 */ 25 25 26 26 use crate::LuminaError; 27 - use crate::database::{PgConn}; 27 + use crate::database::PgConn; 28 28 use cynthia_con::{CynthiaColors, CynthiaStyles}; 29 29 use time::OffsetDateTime; 30 30
+28 -9
server/src/timeline.rs
··· 181 181 async fn fetch_timeline_total_count(db: &DbConn, timeline_id: &str) -> Result<usize, LuminaError> { 182 182 match db { 183 183 DbConn::PgsqlConnection(pg_pool, _redis_pool) => { 184 - let client = pg_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 184 + let client = pg_pool 185 + .get() 186 + .await 187 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 185 188 let timeline_uuid = Uuid::parse_str(timeline_id).map_err(|_| LuminaError::UUidError)?; 186 189 let row = client 187 190 .query_one( ··· 206 209 ) -> Result<Vec<String>, LuminaError> { 207 210 match db { 208 211 DbConn::PgsqlConnection(pg_pool, _redis_pool) => { 209 - let client = pg_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 212 + let client = pg_pool 213 + .get() 214 + .await 215 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 210 216 let timeline_uuid = Uuid::parse_str(timeline_id).map_err(|_| LuminaError::UUidError)?; 211 217 let rows = client 212 218 .query( ··· 238 244 239 245 // Get Redis connection 240 246 let mut redis_conn = match db { 241 - DbConn::PgsqlConnection(_, redis_pool) => { 242 - redis_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))? 243 - } 247 + DbConn::PgsqlConnection(_, redis_pool) => redis_pool 248 + .get() 249 + .await 250 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?, 244 251 }; 245 252 246 253 // Log the requested timeline id for tracking ··· 360 367 // Add to database 361 368 match db { 362 369 DbConn::PgsqlConnection(pg_pool, redis_pool) => { 363 - let client = pg_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 370 + let client = pg_pool 371 + .get() 372 + .await 373 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 364 374 let timeline_uuid = Uuid::parse_str(timeline_id).map_err(|_| LuminaError::UUidError)?; 365 375 let item_uuid = Uuid::parse_str(item_id).map_err(|_| LuminaError::UUidError)?; 366 376 client ··· 372 382 .map_err(LuminaError::Postgres)?; 373 383 374 384 // Invalidate cache 375 - let mut redis_conn = redis_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 385 + let mut redis_conn = redis_pool 386 + .get() 387 + .await 388 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 376 389 if let Err(e) = invalidate_timeline_cache(&mut redis_conn, timeline_id).await { 377 390 error_elog!( 378 391 event_logger, ··· 398 411 // Remove from database 399 412 match db { 400 413 DbConn::PgsqlConnection(pg_pool, redis_pool) => { 401 - let client = pg_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 414 + let client = pg_pool 415 + .get() 416 + .await 417 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 402 418 let timeline_uuid = Uuid::parse_str(timeline_id).map_err(|_| LuminaError::UUidError)?; 403 419 let item_uuid = Uuid::parse_str(item_id).map_err(|_| LuminaError::UUidError)?; 404 420 client ··· 410 426 .map_err(LuminaError::Postgres)?; 411 427 412 428 // Invalidate cache 413 - let mut redis_conn = redis_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 429 + let mut redis_conn = redis_pool 430 + .get() 431 + .await 432 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 414 433 if let Err(e) = invalidate_timeline_cache(&mut redis_conn, timeline_id).await { 415 434 error_elog!( 416 435 event_logger,
+28 -7
server/src/user.rs
··· 62 62 async fn get_hashed_password(self, database: &DbConn) -> Result<String, LuminaError> { 63 63 match database { 64 64 DbConn::PgsqlConnection(pg_pool, _) => { 65 - let client = pg_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 65 + let client = pg_pool 66 + .get() 67 + .await 68 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 66 69 let row = client 67 70 .query_one("SELECT password FROM users WHERE id = $1", &[&self.id]) 68 71 .await ··· 84 87 bcrypt::hash(password, bcrypt::DEFAULT_COST).map_err(|_| LuminaError::BcryptError)?; 85 88 match db { 86 89 DbConn::PgsqlConnection(pg_pool, _) => { 87 - let client = pg_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 90 + let client = pg_pool 91 + .get() 92 + .await 93 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 88 94 // Some username and email validation should be done here 89 95 // Check if the email is already in use 90 96 let email_exists = client ··· 127 133 }; 128 134 match db { 129 135 DbConn::PgsqlConnection(pg_pool, _) => { 130 - let client = pg_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 136 + let client = pg_pool 137 + .get() 138 + .await 139 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 131 140 let user = client 132 141 .query_one( 133 142 &format!("SELECT id, email, username, COALESCE(foreign_instance_id, '') FROM users WHERE {} = $1", identifyer_type), ··· 154 163 let user_id = user.id; 155 164 match db { 156 165 DbConn::PgsqlConnection(pg_pool, _) => { 157 - let client = pg_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 166 + let client = pg_pool 167 + .get() 168 + .await 169 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 158 170 let session_key = Uuid::new_v4().to_string(); 159 171 let id = client 160 172 .query_one( ··· 185 197 ) -> Result<User, LuminaError> { 186 198 match db { 187 199 DbConn::PgsqlConnection(pg_pool, _) => { 188 - let client = pg_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 200 + let client = pg_pool 201 + .get() 202 + .await 203 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 189 204 let user = client 190 205 .query_one("SELECT users.id, users.email, users.username FROM users JOIN sessions ON users.id = sessions.user_id WHERE sessions.session_key = $1", &[&token]) 191 206 .await ··· 211 226 // Check if the email or username is already in use using fastbloom algorithm with Redis, and fallback to DB check if not found. If not in either, we can go on. 212 227 match db { 213 228 DbConn::PgsqlConnection(pg_pool, redis_pool) => { 214 - let client = pg_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 215 - let mut redis_conn = redis_pool.get().await.map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 229 + let client = pg_pool 230 + .get() 231 + .await 232 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 233 + let mut redis_conn = redis_pool 234 + .get() 235 + .await 236 + .map_err(|e| LuminaError::Bb8Pool(e.to_string()))?; 216 237 // fastbloom_rs expects bytes, so we use the string as bytes 217 238 let email_key = String::from("bloom:email"); 218 239 let username_key = String::from("bloom:username");