Parallelize Api
This commit is contained in:
33
src/main.rs
33
src/main.rs
@@ -1,11 +1,10 @@
|
||||
// Prevent console window in addition to Slint window in Windows release builds when, e.g., starting the app via file manager. Ignored on other platforms.
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use std::{mem, ops::Deref};
|
||||
use std::{mem, ops::Deref, sync::Arc};
|
||||
|
||||
use clap::Parser;
|
||||
use immich_sdk::AssetId;
|
||||
use kameo::actor::{ActorRef, Spawn};
|
||||
use slint::{
|
||||
ComponentHandle as _, Model, ModelRc, SharedPixelBuffer, SharedString, ToSharedString,
|
||||
VecModel, Weak,
|
||||
@@ -13,7 +12,7 @@ use slint::{
|
||||
use tracing::Level;
|
||||
|
||||
use crate::{
|
||||
api::{Api, GetAssetThumbnail, GetTimeBucket, GetTimeBuckets, TimeBucketKey},
|
||||
api::{Api, TimeBucketKey},
|
||||
ui::{AppWindow, ImageBucket},
|
||||
};
|
||||
|
||||
@@ -66,8 +65,7 @@ fn main() -> anyhow::Result<()> {
|
||||
|
||||
let immich_config =
|
||||
immich_sdk::Config::new(opt.immich_base_url).with_api_key(opt.immich_api_key);
|
||||
let api = Api::new(immich_sdk::Client::new(immich_config).unwrap());
|
||||
let api_ = Api::spawn(api);
|
||||
let api_ = Api::new(immich_sdk::Client::new(immich_config).unwrap());
|
||||
|
||||
let app = ui::AppWindow::new()?;
|
||||
let global = app.global::<ui::Global>();
|
||||
@@ -76,7 +74,7 @@ fn main() -> anyhow::Result<()> {
|
||||
let app_weak = app.as_weak();
|
||||
let api = api_.clone();
|
||||
tokio::spawn(async move {
|
||||
let Ok(buckets) = api.ask(GetTimeBuckets).await else {
|
||||
let Ok(buckets) = api.get_time_buckets().await else {
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -132,7 +130,7 @@ fn main() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn calculate_timeline_visibility(app: &AppWindow, api: ActorRef<Api>, scroll: f32) {
|
||||
fn calculate_timeline_visibility(app: &AppWindow, api: Arc<Api>, scroll: f32) {
|
||||
let global = app.global::<ui::Global>();
|
||||
global.set_timeline_scroll(scroll);
|
||||
|
||||
@@ -178,7 +176,7 @@ fn calculate_timeline_visibility(app: &AppWindow, api: ActorRef<Api>, scroll: f3
|
||||
}
|
||||
}
|
||||
|
||||
fn calculate_timeline_layout(app: &AppWindow, api: ActorRef<Api>, timeline_width: f32) {
|
||||
fn calculate_timeline_layout(app: &AppWindow, api: Arc<Api>, timeline_width: f32) {
|
||||
let global = app.global::<ui::Global>();
|
||||
let min_image_size = global.get_min_image_size();
|
||||
let image_margin = global.get_image_margin();
|
||||
@@ -267,14 +265,9 @@ fn unload_bucket(time_bucket: &TimeBucketKey, app: &AppWindow) {
|
||||
// TODO: write `bucket` into `buckets?`
|
||||
}
|
||||
|
||||
fn load_bucket(time_bucket: TimeBucketKey, app_weak: Weak<AppWindow>, api: ActorRef<Api>) {
|
||||
fn load_bucket(time_bucket: TimeBucketKey, app_weak: Weak<AppWindow>, api: Arc<Api>) {
|
||||
tokio::spawn(async move {
|
||||
let Ok(api_bucket) = api
|
||||
.ask(GetTimeBucket {
|
||||
time_bucket: time_bucket.clone(),
|
||||
})
|
||||
.await
|
||||
else {
|
||||
let Ok(api_bucket) = api.get_time_bucket(time_bucket.clone()).await else {
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -312,13 +305,13 @@ fn load_bucket(time_bucket: TimeBucketKey, app_weak: Weak<AppWindow>, api: Actor
|
||||
|
||||
fn load_thumbnail(
|
||||
time_bucket: TimeBucketKey,
|
||||
id: AssetId,
|
||||
asset_id: AssetId,
|
||||
app_weak: Weak<AppWindow>,
|
||||
api: ActorRef<Api>,
|
||||
api: Arc<Api>,
|
||||
) {
|
||||
tokio::spawn(async move {
|
||||
tracing::debug!("Fetching thumbnail for {id}");
|
||||
let thumbnail = match api.ask(GetAssetThumbnail { id }).await {
|
||||
tracing::debug!("Fetching thumbnail for {asset_id}");
|
||||
let thumbnail = match api.get_asset_thumbnail(asset_id).await {
|
||||
Ok(thumbnail) => thumbnail,
|
||||
Err(e) => {
|
||||
tracing::error!("{e:?}");
|
||||
@@ -333,7 +326,7 @@ fn load_thumbnail(
|
||||
};
|
||||
let bucket = buckets.row_data(i).expect("i is in the list");
|
||||
|
||||
let id_str = id.to_string();
|
||||
let id_str = asset_id.to_string();
|
||||
let Some(i) = bucket.previews.iter().position(|p| &p.asset_id == &id_str) else {
|
||||
return;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user