You've already forked AstralRinth
forked from didirus/AstralRinth
Labrinth ID cleanup (#3681)
* Put all ID types in the labrinth::models::ids, and reduce code duplication with them * Rewrite labrinth::database::models::ids and rename most DB interface ID structs to be prefixed with DB * Run sqlx prepare --------- Co-authored-by: Alejandro González <7822554+AlexTMjugador@users.noreply.github.com>
This commit is contained in:
@@ -622,12 +622,12 @@ impl AutomatedModerationQueue {
|
||||
|
||||
if !mod_messages.is_empty() {
|
||||
let first_time = database::models::Thread::get(project.thread_id, &pool).await?
|
||||
.map(|x| x.messages.iter().all(|x| x.author_id == Some(database::models::UserId(AUTOMOD_ID)) || x.hide_identity))
|
||||
.map(|x| x.messages.iter().all(|x| x.author_id == Some(database::models::DBUserId(AUTOMOD_ID)) || x.hide_identity))
|
||||
.unwrap_or(true);
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
let id = ThreadMessageBuilder {
|
||||
author_id: Some(database::models::UserId(AUTOMOD_ID)),
|
||||
author_id: Some(database::models::DBUserId(AUTOMOD_ID)),
|
||||
body: MessageBody::Text {
|
||||
body: mod_messages.markdown(true),
|
||||
private: false,
|
||||
@@ -649,7 +649,7 @@ impl AutomatedModerationQueue {
|
||||
|
||||
if mod_messages.should_reject(first_time) {
|
||||
ThreadMessageBuilder {
|
||||
author_id: Some(database::models::UserId(AUTOMOD_ID)),
|
||||
author_id: Some(database::models::DBUserId(AUTOMOD_ID)),
|
||||
body: MessageBody::StatusChange {
|
||||
new_status: ProjectStatus::Rejected,
|
||||
old_status: project.inner.status,
|
||||
@@ -740,7 +740,7 @@ impl AutomatedModerationQueue {
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
ThreadMessageBuilder {
|
||||
author_id: Some(database::models::UserId(AUTOMOD_ID)),
|
||||
author_id: Some(database::models::DBUserId(AUTOMOD_ID)),
|
||||
body: MessageBody::Text {
|
||||
body: str,
|
||||
private: true,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::database::models::pat_item::PersonalAccessToken;
|
||||
use crate::database::models::session_item::Session;
|
||||
use crate::database::models::{
|
||||
DatabaseError, OAuthAccessTokenId, PatId, SessionId, UserId,
|
||||
DBOAuthAccessTokenId, DBPatId, DBSessionId, DBUserId, DatabaseError,
|
||||
};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::routes::internal::session::SessionMetadata;
|
||||
@@ -12,9 +12,9 @@ use std::collections::{HashMap, HashSet};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
pub struct AuthQueue {
|
||||
session_queue: Mutex<HashMap<SessionId, SessionMetadata>>,
|
||||
pat_queue: Mutex<HashSet<PatId>>,
|
||||
oauth_access_token_queue: Mutex<HashSet<OAuthAccessTokenId>>,
|
||||
session_queue: Mutex<HashMap<DBSessionId, SessionMetadata>>,
|
||||
pat_queue: Mutex<HashSet<DBPatId>>,
|
||||
oauth_access_token_queue: Mutex<HashSet<DBOAuthAccessTokenId>>,
|
||||
}
|
||||
|
||||
impl Default for AuthQueue {
|
||||
@@ -32,22 +32,26 @@ impl AuthQueue {
|
||||
oauth_access_token_queue: Mutex::new(HashSet::with_capacity(1000)),
|
||||
}
|
||||
}
|
||||
pub async fn add_session(&self, id: SessionId, metadata: SessionMetadata) {
|
||||
pub async fn add_session(
|
||||
&self,
|
||||
id: DBSessionId,
|
||||
metadata: SessionMetadata,
|
||||
) {
|
||||
self.session_queue.lock().await.insert(id, metadata);
|
||||
}
|
||||
|
||||
pub async fn add_pat(&self, id: PatId) {
|
||||
pub async fn add_pat(&self, id: DBPatId) {
|
||||
self.pat_queue.lock().await.insert(id);
|
||||
}
|
||||
|
||||
pub async fn add_oauth_access_token(
|
||||
&self,
|
||||
id: crate::database::models::OAuthAccessTokenId,
|
||||
id: crate::database::models::DBOAuthAccessTokenId,
|
||||
) {
|
||||
self.oauth_access_token_queue.lock().await.insert(id);
|
||||
}
|
||||
|
||||
pub async fn take_sessions(&self) -> HashMap<SessionId, SessionMetadata> {
|
||||
pub async fn take_sessions(&self) -> HashMap<DBSessionId, SessionMetadata> {
|
||||
let mut queue = self.session_queue.lock().await;
|
||||
let len = queue.len();
|
||||
|
||||
@@ -87,7 +91,7 @@ impl AuthQueue {
|
||||
SET last_login = $2, city = $3, country = $4, ip = $5, os = $6, platform = $7, user_agent = $8
|
||||
WHERE (id = $1)
|
||||
",
|
||||
id as SessionId,
|
||||
id as DBSessionId,
|
||||
Utc::now(),
|
||||
metadata.city,
|
||||
metadata.country,
|
||||
@@ -109,8 +113,8 @@ impl AuthQueue {
|
||||
"
|
||||
)
|
||||
.fetch(&mut *transaction)
|
||||
.map_ok(|x| (SessionId(x.id), x.session, UserId(x.user_id)))
|
||||
.try_collect::<Vec<(SessionId, String, UserId)>>()
|
||||
.map_ok(|x| (DBSessionId(x.id), x.session, DBUserId(x.user_id)))
|
||||
.try_collect::<Vec<(DBSessionId, String, DBUserId)>>()
|
||||
.await?;
|
||||
|
||||
for (id, session, user_id) in expired_ids {
|
||||
@@ -157,7 +161,7 @@ impl AuthQueue {
|
||||
}
|
||||
|
||||
async fn update_oauth_access_token_last_used(
|
||||
oauth_access_token_queue: HashSet<OAuthAccessTokenId>,
|
||||
oauth_access_token_queue: HashSet<DBOAuthAccessTokenId>,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let ids = oauth_access_token_queue.iter().map(|id| id.0).collect_vec();
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! "Database" for Hydra
|
||||
|
||||
use crate::models::users::{UserId, UserStatus};
|
||||
use crate::models::users::UserStatus;
|
||||
use actix_ws::Session;
|
||||
use ariadne::ids::UserId;
|
||||
use dashmap::{DashMap, DashSet};
|
||||
use std::sync::atomic::AtomicU32;
|
||||
use uuid::Uuid;
|
||||
|
||||
Reference in New Issue
Block a user