Skip to content

Commit c807076

Browse files
committed
Fetch more thread info
1 parent a59b18c commit c807076

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

apps/labrinth/src/routes/internal/moderation/tech_review.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
database::{
1313
DBProject,
1414
models::{
15-
DBProjectId, DBThread, DBThreadId, DelphiReportId,
15+
DBProjectId, DBThread, DBThreadId, DBUser, DelphiReportId,
1616
DelphiReportIssueId, ProjectTypeId,
1717
delphi_report_item::{
1818
DelphiReportIssueStatus, DelphiSeverity, ReportIssueDetail,
@@ -24,6 +24,7 @@ use crate::{
2424
ids::{FileId, ProjectId, ThreadId, VersionId},
2525
pats::Scopes,
2626
projects::Project,
27+
threads::Thread,
2728
},
2829
queue::session::AuthQueue,
2930
routes::{ApiError, internal::moderation::Ownership},
@@ -275,7 +276,7 @@ pub struct SearchResponse {
275276
/// Fetched project information for projects in the returned reports.
276277
pub projects: HashMap<ProjectId, ProjectModerationInfo>,
277278
/// Fetched moderation threads for projects in the returned reports.
278-
pub threads: HashMap<ThreadId, DBThread>,
279+
pub threads: HashMap<ThreadId, Thread>,
279280
/// Fetched owner information for projects.
280281
pub ownership: HashMap<ProjectId, Ownership>,
281282
}
@@ -285,6 +286,8 @@ pub struct SearchResponse {
285286
pub struct ProjectModerationInfo {
286287
/// Projecet ID.
287288
pub id: ProjectId,
289+
/// Project moderation thread ID.
290+
pub thread_id: ThreadId,
288291
/// Project name.
289292
pub name: String,
290293
/// The aggregated project typos of the versions of this project
@@ -306,7 +309,7 @@ async fn search_projects(
306309
session_queue: web::Data<AuthQueue>,
307310
search_req: web::Json<SearchProjects>,
308311
) -> Result<web::Json<SearchResponse>, ApiError> {
309-
check_is_moderator_from_headers(
312+
let user = check_is_moderator_from_headers(
310313
&req,
311314
&**pool,
312315
&redis,
@@ -427,11 +430,26 @@ async fn search_projects(
427430
(ProjectId::from(project.inner.id), Project::from(project))
428431
})
429432
.collect::<HashMap<_, _>>();
430-
let threads = DBThread::get_many(&thread_ids, &**pool)
433+
let db_threads = DBThread::get_many(&thread_ids, &**pool)
431434
.await
432-
.wrap_internal_err("failed to fetch threads")?
435+
.wrap_internal_err("failed to fetch threads")?;
436+
let thread_author_ids = db_threads
437+
.iter()
438+
.flat_map(|thread| thread.members.clone())
439+
.collect::<Vec<_>>();
440+
let thread_authors =
441+
DBUser::get_many_ids(&thread_author_ids, &**pool, &redis)
442+
.await
443+
.wrap_internal_err("failed to fetch thread authors")?
444+
.into_iter()
445+
.map(From::from)
446+
.collect::<Vec<_>>();
447+
let threads = db_threads
433448
.into_iter()
434-
.map(|thread| (ThreadId::from(thread.id), thread))
449+
.map(|thread| {
450+
let thread = Thread::from(thread, thread_authors.clone(), &user);
451+
(thread.id, thread)
452+
})
435453
.collect::<HashMap<_, _>>();
436454

437455
let project_list: Vec<Project> = projects.values().cloned().collect();
@@ -454,6 +472,7 @@ async fn search_projects(
454472
id,
455473
ProjectModerationInfo {
456474
id,
475+
thread_id: project.thread_id,
457476
name: project.name,
458477
project_types: project.project_types,
459478
icon_url: project.icon_url,

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ services:
1212
POSTGRES_PASSWORD: labrinth
1313
POSTGRES_HOST_AUTH_METHOD: trust
1414
healthcheck:
15-
test: ['CMD', 'pg_isready']
15+
test: ['CMD', 'pg_isready', '-U', 'labrinth']
1616
interval: 3s
1717
timeout: 5s
1818
retries: 3

0 commit comments

Comments
 (0)