diff --git a/.sqlx/query-3e31ed6194d487b58b8aa0f10438b731232104af05b8e5bd056b69e69c91b703.json b/.sqlx/query-0ac905715f402ec22f28dad89ba60f21644418d1f483aecbcd425a0b69c16bb3.json similarity index 55% rename from .sqlx/query-3e31ed6194d487b58b8aa0f10438b731232104af05b8e5bd056b69e69c91b703.json rename to .sqlx/query-0ac905715f402ec22f28dad89ba60f21644418d1f483aecbcd425a0b69c16bb3.json index 2fd769e..baaea86 100644 --- a/.sqlx/query-3e31ed6194d487b58b8aa0f10438b731232104af05b8e5bd056b69e69c91b703.json +++ b/.sqlx/query-0ac905715f402ec22f28dad89ba60f21644418d1f483aecbcd425a0b69c16bb3.json @@ -1,6 +1,6 @@ { "db_name": "SQLite", - "query": "SELECT name, hash FROM refs WHERE tracked", + "query": "SELECT name, hash, message FROM refs JOIN commits USING (hash) WHERE tracked ", "describe": { "columns": [ { @@ -12,15 +12,21 @@ "name": "hash", "ordinal": 1, "type_info": "Text" + }, + { + "name": "message", + "ordinal": 2, + "type_info": "Text" } ], "parameters": { "Right": 0 }, "nullable": [ + false, false, false ] }, - "hash": "3e31ed6194d487b58b8aa0f10438b731232104af05b8e5bd056b69e69c91b703" + "hash": "0ac905715f402ec22f28dad89ba60f21644418d1f483aecbcd425a0b69c16bb3" } diff --git a/src/repo.rs b/src/repo.rs index c8a3166..a0adc1c 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -1,6 +1,6 @@ //! Utility functions for accessing a [`Repository`]. -use gix::{actor::IdentityRef, Commit}; +use gix::actor::IdentityRef; use crate::somehow; @@ -10,10 +10,3 @@ pub fn format_actor(author: IdentityRef<'_>) -> somehow::Result { author.trim().write_to(&mut buffer)?; Ok(String::from_utf8_lossy(&buffer).to_string()) } - -// TODO Remove this function -pub fn format_commit_short(commit: &Commit<'_>) -> somehow::Result { - let id = commit.id().shorten_or_id(); - let summary = commit.message()?.summary(); - Ok(format!("{id} ({summary})")) -} diff --git a/src/web/index.rs b/src/web/index.rs index 1010011..0459b51 100644 --- a/src/web/index.rs +++ b/src/web/index.rs @@ -1,11 +1,9 @@ -use std::sync::Arc; - use askama::Template; use axum::{extract::State, response::IntoResponse}; -use gix::{prelude::ObjectIdExt, ObjectId, ThreadSafeRepository}; +use futures::TryStreamExt; use sqlx::SqlitePool; -use crate::{config::Config, repo, somehow}; +use crate::{config::Config, db, somehow}; struct Ref { name: String, @@ -19,36 +17,33 @@ struct IndexTemplate { base: String, repo_name: String, current: String, - refs: Vec, + tracked_refs: Vec, } pub async fn get( State(config): State<&'static Config>, State(db): State, - State(repo): State>, ) -> somehow::Result { - let repo = repo.to_thread_local(); - - let rows = sqlx::query!("SELECT name, hash FROM refs WHERE tracked") - .fetch_all(&db) - .await?; - - let mut refs = vec![]; - for row in rows { - let id = row.hash.parse::()?.attach(&repo); - let commit = id.object()?.try_into_commit()?; - - refs.push(Ref { - name: row.name, - hash: row.hash, - short: repo::format_commit_short(&commit)?, - }); - } + let tracked_refs = sqlx::query!( + "\ + SELECT name, hash, message FROM refs \ + JOIN commits USING (hash) \ + WHERE tracked \ + " + ) + .fetch(&db) + .map_ok(|r| Ref { + name: r.name, + short: db::format_commit_short(&r.hash, &r.message), + hash: r.hash, + }) + .try_collect::>() + .await?; Ok(IndexTemplate { base: config.web.base(), repo_name: config.repo.name(), current: "index".to_string(), - refs, + tracked_refs, }) } diff --git a/templates/index.html b/templates/index.html index 98a4211..e88d844 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,7 +5,7 @@ {% block body %}

Tracked refs

- {% for ref in refs %} + {% for ref in tracked_refs %}
{{ ref.name }}
{{ ref.short }}
{% endfor %}