Identify queue items by commit hash, not id

This commit is contained in:
Joscha 2023-08-09 16:19:46 +02:00
parent bf08d00922
commit e5de9ccb97
11 changed files with 42 additions and 186 deletions

View file

@ -2,7 +2,7 @@ use sqlx::{Acquire, SqlitePool};
use time::OffsetDateTime;
use tracing::debug;
use crate::{server::util, somehow};
use crate::somehow;
pub async fn update(db: &SqlitePool) -> somehow::Result<()> {
debug!("Updating queue");
@ -17,13 +17,11 @@ pub async fn update(db: &SqlitePool) -> somehow::Result<()> {
// Insert them into the queue
for row in new {
let id = util::new_run_id();
let date = OffsetDateTime::now_utc();
sqlx::query!(
"INSERT INTO queue (id, hash, date) VALUES (?, ?, ?)",
id,
"INSERT INTO queue (hash, date) VALUES (?, ?)",
row.hash,
date
date,
)
.execute(&mut *conn)
.await?;

View file

@ -2,7 +2,6 @@ mod commit;
mod commit_hash;
mod index;
mod queue;
mod queue_id;
mod r#static;
use axum::{routing::get, Router};
@ -48,7 +47,6 @@ pub async fn run(server: Server) -> somehow::Result<()> {
.route("/commit/:hash", get(commit_hash::get))
.route("/queue/", get(queue::get))
.route("/queue/table", get(queue::get_table))
.route("/queue/:id", get(queue_id::get))
.fallback(get(r#static::static_handler))
.with_state(server.clone());

View file

@ -8,7 +8,7 @@ use crate::{config::Config, server::util, somehow};
use super::{Base, Tab};
struct Task {
id: String,
hash: String,
short: String,
reachable: i64,
since: String,
@ -20,7 +20,6 @@ async fn get_queue(db: &SqlitePool) -> somehow::Result<Vec<Task>> {
let mut tasks = sqlx::query!(
"\
SELECT \
id, \
hash, \
message, \
reachable, \
@ -33,8 +32,8 @@ async fn get_queue(db: &SqlitePool) -> somehow::Result<Vec<Task>> {
)
.fetch(db)
.map_ok(|r| Task {
id: r.id,
short: util::format_commit_short(&r.hash, &r.message),
hash: r.hash,
reachable: r.reachable,
since: util::format_delta_from_now(r.date),
priority: r.priority,
@ -59,12 +58,19 @@ async fn get_queue(db: &SqlitePool) -> somehow::Result<Vec<Task>> {
#[derive(Template)]
#[template(path = "queue_table.html")]
struct QueueTableTemplate {
base: Base,
tasks: Vec<Task>,
}
pub async fn get_table(State(db): State<SqlitePool>) -> somehow::Result<impl IntoResponse> {
pub async fn get_table(
State(config): State<&'static Config>,
State(db): State<SqlitePool>,
) -> somehow::Result<impl IntoResponse> {
let tasks = get_queue(&db).await?;
Ok(QueueTableTemplate { tasks })
Ok(QueueTableTemplate {
base: Base::new(config, Tab::Queue),
tasks,
})
}
#[derive(Template)]
#[template(path = "queue.html")]
@ -77,9 +83,10 @@ pub async fn get(
State(config): State<&'static Config>,
State(db): State<SqlitePool>,
) -> somehow::Result<impl IntoResponse> {
let base = Base::new(config, Tab::Queue);
let tasks = get_queue(&db).await?;
Ok(QueueTemplate {
base: Base::new(config, Tab::Queue),
table: QueueTableTemplate { tasks },
base: base.clone(),
table: QueueTableTemplate { base, tasks },
})
}

View file

@ -1,65 +0,0 @@
use askama::Template;
use axum::{
extract::{Path, State},
http::StatusCode,
response::{IntoResponse, Response},
};
use sqlx::SqlitePool;
use crate::{config::Config, server::util, somehow};
use super::{Base, Tab};
#[derive(Template)]
#[template(path = "queue_id.html")]
struct QueueIdTemplate {
base: Base,
// Task
id: String,
hash: String,
date: String,
priority: i64,
// Commit
summary: String,
short: String,
reachable: i64,
}
pub async fn get(
Path(id): Path<String>,
State(config): State<&'static Config>,
State(db): State<SqlitePool>,
) -> somehow::Result<Response> {
let Some(task) = sqlx::query!(
"\
SELECT \
id, \
hash, \
date AS \"date: time::OffsetDateTime\", \
priority, \
message, \
reachable \
FROM queue \
JOIN commits USING (hash) \
WHERE id = ? \
",
id
)
.fetch_optional(&db)
.await?
else {
return Ok(StatusCode::NOT_FOUND.into_response());
};
Ok(QueueIdTemplate {
base: Base::new(config, Tab::Queue),
date: util::format_time(task.date),
id: task.id,
priority: task.priority,
summary: util::format_commit_summary(&task.message),
short: util::format_commit_short(&task.hash, &task.message),
hash: task.hash,
reachable: task.reachable,
}
.into_response())
}