refactor: split ImageRefPort into ImageRefCommand and ImageRefQuery

This commit is contained in:
2026-05-12 15:10:49 +02:00
parent 696e3e170c
commit cea414fe60
8 changed files with 57 additions and 41 deletions

View File

@@ -2,8 +2,9 @@ use std::sync::Arc;
use anyhow::Context;
use domain::ports::{
DiaryRepository, ImageRefPort, ImportProfileRepository, ImportSessionRepository,
MovieProfileRepository, MovieRepository, ReviewRepository, StatsRepository, UserRepository,
DiaryRepository, ImageRefCommand, ImageRefQuery, ImportProfileRepository,
ImportSessionRepository, MovieProfileRepository, MovieRepository, ReviewRepository,
StatsRepository, UserRepository,
};
pub enum DbPool {
@@ -22,7 +23,8 @@ pub struct Repos {
pub import_session: Arc<dyn ImportSessionRepository>,
pub import_profile: Arc<dyn ImportProfileRepository>,
pub movie_profile: Arc<dyn MovieProfileRepository>,
pub image_ref: Arc<dyn ImageRefPort>,
pub image_ref_command: Arc<dyn ImageRefCommand>,
pub image_ref_query: Arc<dyn ImageRefQuery>,
}
pub async fn connect(database_url: &str, backend: &str) -> anyhow::Result<(Repos, DbPool)> {
@@ -31,15 +33,19 @@ pub async fn connect(database_url: &str, backend: &str) -> anyhow::Result<(Repos
"postgres" => {
let (pool, m, r, d, s, u, is, ip, mp) =
postgres::wire(database_url).await.context("PostgreSQL connection failed")?;
let image_ref = postgres::create_image_ref(pool.clone());
Ok((Repos { movie: m, review: r, diary: d, stats: s, user: u, import_session: is, import_profile: ip, movie_profile: mp, image_ref }, DbPool::Postgres(pool)))
let (image_ref_command, image_ref_query) = postgres::create_image_ref(pool.clone());
Ok((Repos { movie: m, review: r, diary: d, stats: s, user: u,
import_session: is, import_profile: ip, movie_profile: mp,
image_ref_command, image_ref_query }, DbPool::Postgres(pool)))
}
#[cfg(feature = "sqlite")]
_ => {
let (pool, m, r, d, s, u, is, ip, mp) =
sqlite::wire(database_url).await.context("SQLite connection failed")?;
let image_ref = sqlite::create_image_ref(pool.clone());
Ok((Repos { movie: m, review: r, diary: d, stats: s, user: u, import_session: is, import_profile: ip, movie_profile: mp, image_ref }, DbPool::Sqlite(pool)))
let (image_ref_command, image_ref_query) = sqlite::create_image_ref(pool.clone());
Ok((Repos { movie: m, review: r, diary: d, stats: s, user: u,
import_session: is, import_profile: ip, movie_profile: mp,
image_ref_command, image_ref_query }, DbPool::Sqlite(pool)))
}
#[cfg(not(feature = "sqlite"))]
_ => anyhow::bail!("DATABASE_BACKEND={backend} is not supported by this build"),

View File

@@ -31,8 +31,8 @@ async fn main() -> anyhow::Result<()> {
let (repos, db_pool) = db::connect(&database_url, &backend).await?;
let (event_publisher_arc, consumer_arc) = event_bus::create(&db_pool).await?;
// Save image_ref before ctx consumes repos.
let image_ref = Arc::clone(&repos.image_ref);
let image_ref_command = Arc::clone(&repos.image_ref_command);
let image_ref_query = Arc::clone(&repos.image_ref_query);
// Clone refs federation handler needs before ctx consumes them.
#[cfg(feature = "federation")]
@@ -91,7 +91,8 @@ async fn main() -> anyhow::Result<()> {
let conversion = image_converter::build(
Arc::clone(&ctx.image_storage),
image_ref,
image_ref_command,
image_ref_query,
Arc::clone(&ctx.event_publisher),
)?;