vote: Change graph display condition, don't fetch for admin

Now, the graph will only show when everyone has voted and the week is no longer
the last one active.
This is to minimize information gathering by looking during voting.

Don't fetch the vote data for the admin : it is not used, so no need to
query the database.

Update README with new TODOs and clean up main includes a bit.
This commit is contained in:
trotFunky 2024-07-26 00:45:53 +01:00
parent f41f5142c9
commit 635716c04b
4 changed files with 15 additions and 5 deletions

View file

@ -2,6 +2,7 @@ use std::collections::hash_map::Entry;
use std::collections::HashMap;
use rocket::fairing::AdHoc;
use rocket::form::Form;
use rocket::futures::TryFutureExt;
use rocket::http::CookieJar;
use rocket::response::Redirect;
use rocket::serde::{Serialize, Deserialize};
@ -61,7 +62,7 @@ pub async fn vote(week: u8, form: Form<VoteForm>,
}
None => {
debug!("Player {:?} voting {voted_id} for truth {truth_id}", user.id);
// TODO: Find a way to use only one statement ?
// TODO: Find a way to use only one statement ? --> query_many
// Cannot all launch and await because all connect to DB
match sqlx::query("INSERT INTO Votes (truth_id, voter_id, voted_id) VALUES ($1, $2, $3);")
.bind(truth_id)
@ -110,7 +111,12 @@ pub async fn fetch_vote_data(week: u8, mut db: Connection<database::Db>) -> Opti
});
let vote_count = raw_votes.iter().fold(0, |count, votes| {count + votes.votes});
if vote_count < 17 {
// Only show the graph if we have all the votes and this is not the last week.
// FIXME: Make the 42 not hardcoded
if vote_count < 42 || week != sqlx::query_scalar("SELECT number from Weeks WHERE number == $1 AND is_last_week == 1;")
.bind(week)
.fetch_optional(&mut **db)
.await.unwrap_or(Some(0)).unwrap_or(0) {
return None;
}