Skip to content

Commit 470308f

Browse files
tegiozcynthia-sg
andauthored
Audit: display vote details for votes in progress (#681)
Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com> Signed-off-by: Cintia Sánchez García <cynthiasg@icloud.com> Co-authored-by: Cintia Sánchez García <cynthiasg@icloud.com>
1 parent a2ede44 commit 470308f

5 files changed

Lines changed: 558 additions & 170 deletions

File tree

src/db.rs

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
//! This module defines an abstraction layer over the database.
22
33
use std::sync::Arc;
4-
#[cfg(not(test))]
5-
use std::time::Duration;
64

75
use anyhow::Result;
86
use async_trait::async_trait;
9-
#[cfg(not(test))]
10-
use cached::proc_macro::cached;
117
use deadpool_postgres::{Pool, Transaction};
128
#[cfg(test)]
139
use mockall::automock;
14-
use tokio_postgres::{Client, types::Json};
10+
use tokio_postgres::types::Json;
1511
use uuid::Uuid;
1612

1713
use crate::{
@@ -43,6 +39,9 @@ pub(crate) trait DB {
4339
/// Get pending status checks.
4440
async fn get_pending_status_checks(&self) -> Result<Vec<CheckVoteInput>>;
4541

42+
/// Get vote by id.
43+
async fn get_vote(&self, vote_id: Uuid) -> Result<Option<Vote>>;
44+
4645
/// Check if the issue/pr provided has a vote.
4746
async fn has_vote(&self, repository_full_name: &str, issue_number: i64) -> Result<bool>;
4847

@@ -248,6 +247,16 @@ impl DB for PgDB {
248247
Ok(inputs)
249248
}
250249

250+
/// [`DB::get_vote`]
251+
async fn get_vote(&self, vote_id: Uuid) -> Result<Option<Vote>> {
252+
let db = self.pool.get().await?;
253+
let vote = db
254+
.query_opt("select * from vote where vote_id = $1::uuid", &[&vote_id])
255+
.await?
256+
.map(|row| Vote::from(&row));
257+
Ok(vote)
258+
}
259+
251260
/// [`DB::has_vote`]
252261
async fn has_vote(&self, repository_full_name: &str, issue_number: i64) -> Result<bool> {
253262
let db = self.pool.get().await?;
@@ -289,36 +298,22 @@ impl DB for PgDB {
289298

290299
/// [`DB::list_votes`]
291300
async fn list_votes(&self, repository_full_name: &str) -> Result<Vec<Vote>> {
292-
#[cfg_attr(
293-
not(test),
294-
cached(
295-
time = 900,
296-
key = "String",
297-
convert = r#"{ repository_full_name.to_owned() }"#,
298-
sync_writes = "by_key",
299-
result = true
301+
let db = self.pool.get().await?;
302+
let votes = db
303+
.query(
304+
"
305+
select *
306+
from vote
307+
where repository_full_name = $1::text
308+
order by created_at desc
309+
",
310+
&[&repository_full_name],
300311
)
301-
)]
302-
async fn inner(client: &Client, repository_full_name: &str) -> Result<Vec<Vote>> {
303-
let votes = client
304-
.query(
305-
"
306-
select *
307-
from vote
308-
where repository_full_name = $1::text
309-
order by created_at desc
310-
",
311-
&[&repository_full_name],
312-
)
313-
.await?
314-
.iter()
315-
.map(Vote::from)
316-
.collect();
317-
Ok(votes)
318-
}
319-
320-
let client = self.pool.get().await?;
321-
inner(client.as_ref(), repository_full_name).await
312+
.await?
313+
.iter()
314+
.map(Vote::from)
315+
.collect();
316+
Ok(votes)
322317
}
323318

324319
/// [`DB::store_vote`]

0 commit comments

Comments
 (0)