refactor: fewer non-macro queries
Some checks failed
/ integration-test--firefox (push) Failing after 3m5s

This commit is contained in:
Robert Perce 2026-01-26 22:14:58 -06:00
parent 69e23fd9bb
commit 84c41dda4d
5 changed files with 119 additions and 111 deletions

View file

@ -76,17 +76,7 @@ mod get {
let user = auth_session.user.unwrap();
let pool = &state.db(&user).pool;
let contact: HydratedContact = sqlx::query_as(
"select *, (
select string_agg(name,'\x1c' order by sort)
from names where contact_id = c.id
) as names
from contacts c
where c.id = $1",
)
.bind(contact_id)
.fetch_one(pool)
.await?;
let contact = HydratedContact::load(contact_id, pool).await?;
let entries: Vec<JournalEntry> = sqlx::query_as(
"select distinct j.id, j.value, j.date from journal_entries j
@ -231,29 +221,7 @@ mod get {
layout: Layout,
) -> Result<Markup, AppError> {
let pool = &state.db(&auth_session.user.unwrap()).pool;
let contact: HydratedContact = sqlx::query_as(
"select *, (
select string_agg(name,'\x1c' order by sort)
from names where contact_id = c.id
) as names, (
select jes.date from journal_entries jes
join mentions m on m.entity_id = jes.id
where
m.entity_type = $1 and (
m.url = '/contact/'||c.id
or m.url in (
select '/group/'||name
from groups
where contact_id = c.id
))
order by jes.date desc limit 1
) as last_mention_date from contacts c
where c.id = $2",
)
.bind(MentionHostType::JournalEntry as DbId)
.bind(contact_id)
.fetch_one(pool)
.await?;
let contact = HydratedContact::load(contact_id, pool).await?;
let addresses: Vec<Address> = sqlx::query_as!(
Address,