commit a7074636883b023d7b4604cb426e56c94151199c parent 521122d8f93b921132216a811a1d714ffe7c35e0 Author: kernelkind <kernelkind@gmail.com> Date: Fri, 21 Nov 2025 13:11:53 -0700 tmp(refactor): rename current jobs stuff to Old so I can make smaller commits for the jobs refactor Signed-off-by: kernelkind <kernelkind@gmail.com> Diffstat:
24 files changed, 238 insertions(+), 237 deletions(-)
diff --git a/crates/notedeck/src/jobs/cache.rs b/crates/notedeck/src/jobs/cache.rs @@ -1,154 +0,0 @@ -use egui::TextureHandle; -use hashbrown::{hash_map::RawEntryMut, HashMap}; -use poll_promise::Promise; - -use crate::jobs::JobPool; - -#[derive(Default)] -pub struct JobsCache { - jobs: HashMap<JobIdOwned, JobState>, -} - -pub enum JobState { - Pending(Promise<Option<Result<Job, JobError>>>), - Error(JobError), - Completed(Job), -} - -pub enum JobError { - InvalidParameters, -} - -#[derive(Debug)] -pub enum JobParams<'a> { - Blurhash(BlurhashParams<'a>), -} - -#[derive(Debug)] -pub enum JobParamsOwned { - Blurhash(BlurhashParamsOwned), -} - -impl<'a> From<BlurhashParams<'a>> for BlurhashParamsOwned { - fn from(params: BlurhashParams<'a>) -> Self { - BlurhashParamsOwned { - blurhash: params.blurhash.to_owned(), - url: params.url.to_owned(), - ctx: params.ctx.clone(), - } - } -} - -impl<'a> From<JobParams<'a>> for JobParamsOwned { - fn from(params: JobParams<'a>) -> Self { - match params { - JobParams::Blurhash(bp) => JobParamsOwned::Blurhash(bp.into()), - } - } -} - -#[derive(Debug)] -pub struct BlurhashParams<'a> { - pub blurhash: &'a str, - pub url: &'a str, - pub ctx: &'a egui::Context, -} - -#[derive(Debug)] -pub struct BlurhashParamsOwned { - pub blurhash: String, - pub url: String, - pub ctx: egui::Context, -} - -impl JobsCache { - pub fn get_or_insert_with< - 'a, - F: FnOnce(Option<JobParamsOwned>) -> Result<Job, JobError> + Send + 'static, - >( - &'a mut self, - job_pool: &mut JobPool, - jobid: &JobId, - params: Option<JobParams>, - run_job: F, - ) -> &'a mut JobState { - match self.jobs.raw_entry_mut().from_key(jobid) { - RawEntryMut::Occupied(entry) => 's: { - let mut state = entry.into_mut(); - - let JobState::Pending(promise) = &mut state else { - break 's state; - }; - - let Some(res) = promise.ready_mut() else { - break 's state; - }; - - let Some(res) = res.take() else { - tracing::error!("Failed to take the promise for job: {:?}", jobid); - break 's state; - }; - - *state = match res { - Ok(j) => JobState::Completed(j), - Err(e) => JobState::Error(e), - }; - - state - } - RawEntryMut::Vacant(entry) => { - let owned_params = params.map(JobParams::into); - let wrapped: Box<dyn FnOnce() -> Option<Result<Job, JobError>> + Send + 'static> = - Box::new(move || Some(run_job(owned_params))); - - let promise = Promise::spawn_async(job_pool.schedule(wrapped)); - - let (_, state) = entry.insert(jobid.into(), JobState::Pending(promise)); - - state - } - } - } - - pub fn get(&self, jobid: &JobId) -> Option<&JobState> { - self.jobs.get(jobid) - } -} - -impl<'a> From<&JobId<'a>> for JobIdOwned { - fn from(jobid: &JobId<'a>) -> Self { - match jobid { - JobId::Blurhash(s) => JobIdOwned::Blurhash(s.to_string()), - } - } -} - -impl hashbrown::Equivalent<JobIdOwned> for JobId<'_> { - fn equivalent(&self, key: &JobIdOwned) -> bool { - match (self, key) { - (JobId::Blurhash(a), JobIdOwned::Blurhash(b)) => *a == b.as_str(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Hash)] -enum JobIdOwned { - Blurhash(String), // image URL -} - -#[derive(Debug, Hash)] -pub enum JobId<'a> { - Blurhash(&'a str), // image URL -} - -pub enum Job { - Blurhash(Option<TextureHandle>), -} - -impl std::fmt::Debug for Job { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - match self { - Job::Blurhash(_) => write!(f, "Blurhash"), - } - } -} diff --git a/crates/notedeck/src/jobs/cache_old.rs b/crates/notedeck/src/jobs/cache_old.rs @@ -0,0 +1,154 @@ +use egui::TextureHandle; +use hashbrown::{hash_map::RawEntryMut, HashMap}; +use poll_promise::Promise; + +use crate::jobs::JobPool; + +#[derive(Default)] +pub struct JobsCacheOld { + jobs: HashMap<JobIdOwned, JobState>, +} + +pub enum JobState { + Pending(Promise<Option<Result<Job, JobError>>>), + Error(JobError), + Completed(Job), +} + +pub enum JobError { + InvalidParameters, +} + +#[derive(Debug)] +pub enum JobParams<'a> { + Blurhash(BlurhashParams<'a>), +} + +#[derive(Debug)] +pub enum JobParamsOwned { + Blurhash(BlurhashParamsOwned), +} + +impl<'a> From<BlurhashParams<'a>> for BlurhashParamsOwned { + fn from(params: BlurhashParams<'a>) -> Self { + BlurhashParamsOwned { + blurhash: params.blurhash.to_owned(), + url: params.url.to_owned(), + ctx: params.ctx.clone(), + } + } +} + +impl<'a> From<JobParams<'a>> for JobParamsOwned { + fn from(params: JobParams<'a>) -> Self { + match params { + JobParams::Blurhash(bp) => JobParamsOwned::Blurhash(bp.into()), + } + } +} + +#[derive(Debug)] +pub struct BlurhashParams<'a> { + pub blurhash: &'a str, + pub url: &'a str, + pub ctx: &'a egui::Context, +} + +#[derive(Debug)] +pub struct BlurhashParamsOwned { + pub blurhash: String, + pub url: String, + pub ctx: egui::Context, +} + +impl JobsCacheOld { + pub fn get_or_insert_with< + 'a, + F: FnOnce(Option<JobParamsOwned>) -> Result<Job, JobError> + Send + 'static, + >( + &'a mut self, + job_pool: &mut JobPool, + jobid: &JobIdOld, + params: Option<JobParams>, + run_job: F, + ) -> &'a mut JobState { + match self.jobs.raw_entry_mut().from_key(jobid) { + RawEntryMut::Occupied(entry) => 's: { + let mut state = entry.into_mut(); + + let JobState::Pending(promise) = &mut state else { + break 's state; + }; + + let Some(res) = promise.ready_mut() else { + break 's state; + }; + + let Some(res) = res.take() else { + tracing::error!("Failed to take the promise for job: {:?}", jobid); + break 's state; + }; + + *state = match res { + Ok(j) => JobState::Completed(j), + Err(e) => JobState::Error(e), + }; + + state + } + RawEntryMut::Vacant(entry) => { + let owned_params = params.map(JobParams::into); + let wrapped: Box<dyn FnOnce() -> Option<Result<Job, JobError>> + Send + 'static> = + Box::new(move || Some(run_job(owned_params))); + + let promise = Promise::spawn_async(job_pool.schedule(wrapped)); + + let (_, state) = entry.insert(jobid.into(), JobState::Pending(promise)); + + state + } + } + } + + pub fn get(&self, jobid: &JobIdOld) -> Option<&JobState> { + self.jobs.get(jobid) + } +} + +impl<'a> From<&JobIdOld<'a>> for JobIdOwned { + fn from(jobid: &JobIdOld<'a>) -> Self { + match jobid { + JobIdOld::Blurhash(s) => JobIdOwned::Blurhash(s.to_string()), + } + } +} + +impl hashbrown::Equivalent<JobIdOwned> for JobIdOld<'_> { + fn equivalent(&self, key: &JobIdOwned) -> bool { + match (self, key) { + (JobIdOld::Blurhash(a), JobIdOwned::Blurhash(b)) => *a == b.as_str(), + } + } +} + +#[derive(Debug, PartialEq, Eq, Clone, Hash)] +enum JobIdOwned { + Blurhash(String), // image URL +} + +#[derive(Debug, Hash)] +pub enum JobIdOld<'a> { + Blurhash(&'a str), // image URL +} + +pub enum Job { + Blurhash(Option<TextureHandle>), +} + +impl std::fmt::Debug for Job { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Job::Blurhash(_) => write!(f, "Blurhash"), + } + } +} diff --git a/crates/notedeck/src/jobs/mod.rs b/crates/notedeck/src/jobs/mod.rs @@ -1,7 +1,7 @@ -mod cache; +mod cache_old; mod job_pool; -pub use cache::{ - BlurhashParams, Job, JobError, JobId, JobParams, JobParamsOwned, JobState, JobsCache, +pub use cache_old::{ + BlurhashParams, Job, JobError, JobIdOld, JobParams, JobParamsOwned, JobState, JobsCacheOld, }; pub use job_pool::JobPool; diff --git a/crates/notedeck/src/lib.rs b/crates/notedeck/src/lib.rs @@ -59,7 +59,8 @@ pub use imgcache::{ TexturedImage, TexturesCache, }; pub use jobs::{ - BlurhashParams, Job, JobError, JobId, JobParams, JobParamsOwned, JobPool, JobState, JobsCache, + BlurhashParams, Job, JobError, JobIdOld, JobParams, JobParamsOwned, JobPool, JobState, + JobsCacheOld, }; pub use media::{ compute_blurhash, update_imeta_blurhashes, ImageMetadata, ImageType, MediaAction, diff --git a/crates/notedeck_clndash/src/ui.rs b/crates/notedeck_clndash/src/ui.rs @@ -56,7 +56,7 @@ pub fn note_hover_ui( global_wallet: ctx.global_wallet, }; - let mut jobs = notedeck::JobsCache::default(); + let mut jobs = notedeck::JobsCacheOld::default(); let options = notedeck_ui::NoteOptions::default(); notedeck_ui::ProfilePic::from_profile_or_default(note_context.img_cache, author.as_ref()) diff --git a/crates/notedeck_columns/src/accounts/mod.rs b/crates/notedeck_columns/src/accounts/mod.rs @@ -1,7 +1,7 @@ use enostr::{FullKeypair, Pubkey}; use nostrdb::{Ndb, Transaction}; -use notedeck::{Accounts, AppContext, JobsCache, Localization, SingleUnkIdAction, UnknownIds}; +use notedeck::{Accounts, AppContext, JobsCacheOld, Localization, SingleUnkIdAction, UnknownIds}; use notedeck_ui::nip51_set::Nip51SetUiCache; pub use crate::accounts::route::AccountsResponse; @@ -77,7 +77,7 @@ pub struct AddAccountAction { pub fn render_accounts_route( ui: &mut egui::Ui, app_ctx: &mut AppContext, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, login_state: &mut AcquireKeyState, onboarding: &mut Onboarding, follow_packs_ui: &mut Nip51SetUiCache, diff --git a/crates/notedeck_columns/src/app.rs b/crates/notedeck_columns/src/app.rs @@ -21,7 +21,7 @@ use enostr::{ClientMessage, PoolRelay, Pubkey, RelayEvent, RelayMessage, RelayPo use nostrdb::Transaction; use notedeck::{ tr, ui::is_narrow, Accounts, AppAction, AppContext, AppResponse, DataPath, DataPathType, - FilterState, Images, JobsCache, Localization, NotedeckOptions, SettingsHandler, UnknownIds, + FilterState, Images, JobsCacheOld, Localization, NotedeckOptions, SettingsHandler, UnknownIds, }; use notedeck_ui::{ media::{MediaViewer, MediaViewerFlags, MediaViewerState}, @@ -48,7 +48,7 @@ pub struct Damus { pub timeline_cache: TimelineCache, pub subscriptions: Subscriptions, pub support: Support, - pub jobs: JobsCache, + pub jobs: JobsCacheOld, pub threads: Threads, //frame_history: crate::frame_history::FrameHistory, @@ -568,7 +568,7 @@ impl Damus { let support = Support::new(app_context.path); let note_options = get_note_options(parsed_args, app_context.settings); - let jobs = JobsCache::default(); + let jobs = JobsCacheOld::default(); let threads = Threads::default(); Self { @@ -635,7 +635,7 @@ impl Damus { options, decks_cache, unrecognized_args: BTreeSet::default(), - jobs: JobsCache::default(), + jobs: JobsCacheOld::default(), threads: Threads::default(), onboarding: Onboarding::default(), hovered_column: None, diff --git a/crates/notedeck_columns/src/timeline/route.rs b/crates/notedeck_columns/src/timeline/route.rs @@ -6,7 +6,7 @@ use crate::{ }; use enostr::Pubkey; -use notedeck::{JobsCache, NoteContext}; +use notedeck::{JobsCacheOld, NoteContext}; use notedeck_ui::NoteOptions; #[allow(clippy::too_many_arguments)] @@ -18,7 +18,7 @@ pub fn render_timeline_route( depth: usize, ui: &mut egui::Ui, note_context: &mut NoteContext, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, scroll_to_top: bool, ) -> BodyResponse<RenderNavAction> { match kind { @@ -74,7 +74,7 @@ pub fn render_thread_route( mut note_options: NoteOptions, ui: &mut egui::Ui, note_context: &mut NoteContext, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, ) -> BodyResponse<RenderNavAction> { // don't truncate thread notes for now, since they are // default truncated everywher eelse @@ -103,7 +103,7 @@ pub fn render_profile_route( ui: &mut egui::Ui, note_options: NoteOptions, note_context: &mut NoteContext, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, ) -> BodyResponse<RenderNavAction> { let profile_view = ProfileView::new( pubkey, diff --git a/crates/notedeck_columns/src/ui/note/post.rs b/crates/notedeck_columns/src/ui/note/post.rs @@ -18,7 +18,7 @@ use notedeck::media::AnimationMode; #[cfg(target_os = "android")] use notedeck::platform::android::try_open_file_picker; use notedeck::platform::get_next_selected_file; -use notedeck::{get_render_state, JobsCache, PixelDimensions, RenderState}; +use notedeck::{get_render_state, JobsCacheOld, PixelDimensions, RenderState}; use notedeck::{ name::get_display_name, supported_mime_hosted_at_url, tr, Localization, NoteAction, NoteContext, }; @@ -39,7 +39,7 @@ pub struct PostView<'a, 'd> { poster: FilledKeypair<'a>, inner_rect: egui::Rect, note_options: NoteOptions, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, animation_mode: AnimationMode, } @@ -112,7 +112,7 @@ impl<'a, 'd> PostView<'a, 'd> { poster: FilledKeypair<'a>, inner_rect: egui::Rect, note_options: NoteOptions, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, ) -> Self { let animation_mode = if note_options.contains(NoteOptions::NoAnimations) { AnimationMode::NoAnimation @@ -837,7 +837,7 @@ mod preview { pub struct PostPreview { draft: Draft, poster: FullKeypair, - jobs: JobsCache, + jobs: JobsCacheOld, } impl PostPreview { diff --git a/crates/notedeck_columns/src/ui/note/quote_repost.rs b/crates/notedeck_columns/src/ui/note/quote_repost.rs @@ -7,7 +7,7 @@ use crate::{ use egui::ScrollArea; use enostr::{FilledKeypair, NoteId}; -use notedeck::{JobsCache, NoteContext}; +use notedeck::{JobsCacheOld, NoteContext}; use notedeck_ui::NoteOptions; pub struct QuoteRepostView<'a, 'd> { @@ -18,7 +18,7 @@ pub struct QuoteRepostView<'a, 'd> { scroll_id: egui::Id, inner_rect: egui::Rect, note_options: NoteOptions, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, } impl<'a, 'd> QuoteRepostView<'a, 'd> { @@ -30,7 +30,7 @@ impl<'a, 'd> QuoteRepostView<'a, 'd> { quoting_note: &'a nostrdb::Note<'a>, inner_rect: egui::Rect, note_options: NoteOptions, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, col: usize, ) -> Self { QuoteRepostView { diff --git a/crates/notedeck_columns/src/ui/note/reply.rs b/crates/notedeck_columns/src/ui/note/reply.rs @@ -7,7 +7,7 @@ use crate::ui::{ use egui::{Rect, Response, ScrollArea, Ui}; use enostr::{FilledKeypair, NoteId}; -use notedeck::{JobsCache, NoteContext}; +use notedeck::{JobsCacheOld, NoteContext}; use notedeck_ui::{NoteOptions, NoteView, ProfilePic}; pub struct PostReplyView<'a, 'd> { @@ -18,7 +18,7 @@ pub struct PostReplyView<'a, 'd> { scroll_id: egui::Id, inner_rect: egui::Rect, note_options: NoteOptions, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, } impl<'a, 'd> PostReplyView<'a, 'd> { @@ -30,7 +30,7 @@ impl<'a, 'd> PostReplyView<'a, 'd> { note: &'a nostrdb::Note<'a>, inner_rect: egui::Rect, note_options: NoteOptions, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, col: usize, ) -> Self { PostReplyView { diff --git a/crates/notedeck_columns/src/ui/onboarding.rs b/crates/notedeck_columns/src/ui/onboarding.rs @@ -2,7 +2,7 @@ use std::mem; use egui::{Layout, ScrollArea}; use nostrdb::Ndb; -use notedeck::{tr, Images, JobPool, JobsCache, Localization}; +use notedeck::{tr, Images, JobPool, JobsCacheOld, Localization}; use notedeck_ui::{ colors, nip51_set::{Nip51SetUiCache, Nip51SetWidget, Nip51SetWidgetAction, Nip51SetWidgetFlags}, @@ -18,7 +18,7 @@ pub struct FollowPackOnboardingView<'a> { images: &'a mut Images, loc: &'a mut Localization, job_pool: &'a mut JobPool, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, } pub enum OnboardingResponse { @@ -39,7 +39,7 @@ impl<'a> FollowPackOnboardingView<'a> { images: &'a mut Images, loc: &'a mut Localization, job_pool: &'a mut JobPool, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, ) -> Self { Self { onboarding, diff --git a/crates/notedeck_columns/src/ui/profile/mod.rs b/crates/notedeck_columns/src/ui/profile/mod.rs @@ -17,7 +17,7 @@ use crate::{ ui::timeline::{tabs_ui, TimelineTabView}, }; use notedeck::{ - name::get_display_name, profile::get_profile_url, IsFollowing, JobsCache, NoteAction, + name::get_display_name, profile::get_profile_url, IsFollowing, JobsCacheOld, NoteAction, NoteContext, NotedeckTextStyle, }; use notedeck_ui::{ @@ -32,7 +32,7 @@ pub struct ProfileView<'a, 'd> { timeline_cache: &'a mut TimelineCache, note_options: NoteOptions, note_context: &'a mut NoteContext<'d>, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, } pub enum ProfileViewAction { @@ -58,7 +58,7 @@ impl<'a, 'd> ProfileView<'a, 'd> { timeline_cache: &'a mut TimelineCache, note_options: NoteOptions, note_context: &'a mut NoteContext<'d>, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, ) -> Self { ProfileView { pubkey, diff --git a/crates/notedeck_columns/src/ui/search/mod.rs b/crates/notedeck_columns/src/ui/search/mod.rs @@ -11,7 +11,7 @@ use egui_winit::clipboard::Clipboard; use nostrdb::{Filter, Ndb, ProfileRecord, Transaction}; use notedeck::{ fonts::get_font_size, name::get_display_name, profile::get_profile_url, tr, tr_plural, Images, - JobsCache, Localization, NoteAction, NoteContext, NoteRef, NotedeckTextStyle, + JobsCacheOld, Localization, NoteAction, NoteContext, NoteRef, NotedeckTextStyle, }; use notedeck_ui::{ @@ -33,7 +33,7 @@ pub struct SearchView<'a, 'd> { note_options: NoteOptions, txn: &'a Transaction, note_context: &'a mut NoteContext<'d>, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, } impl<'a, 'd> SearchView<'a, 'd> { @@ -42,7 +42,7 @@ impl<'a, 'd> SearchView<'a, 'd> { note_options: NoteOptions, query: &'a mut SearchQueryState, note_context: &'a mut NoteContext<'d>, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, ) -> Self { Self { txn, diff --git a/crates/notedeck_columns/src/ui/settings.rs b/crates/notedeck_columns/src/ui/settings.rs @@ -6,7 +6,7 @@ use egui_extras::{Size, StripBuilder}; use enostr::NoteId; use nostrdb::Transaction; use notedeck::{ - tr, ui::richtext_small, Images, JobsCache, LanguageIdentifier, Localization, NoteContext, + tr, ui::richtext_small, Images, JobsCacheOld, LanguageIdentifier, Localization, NoteContext, NotedeckTextStyle, Settings, SettingsHandler, DEFAULT_MAX_HASHTAGS_PER_NOTE, DEFAULT_NOTE_BODY_FONT_SIZE, }; @@ -109,7 +109,7 @@ pub struct SettingsView<'a> { settings: &'a mut Settings, note_context: &'a mut NoteContext<'a>, note_options: &'a mut NoteOptions, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, } fn settings_group<S>(ui: &mut egui::Ui, title: S, contents: impl FnOnce(&mut egui::Ui)) @@ -136,7 +136,7 @@ impl<'a> SettingsView<'a> { settings: &'a mut Settings, note_context: &'a mut NoteContext<'a>, note_options: &'a mut NoteOptions, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, ) -> Self { Self { settings, diff --git a/crates/notedeck_columns/src/ui/thread.rs b/crates/notedeck_columns/src/ui/thread.rs @@ -2,7 +2,7 @@ use egui::InnerResponse; use egui_virtual_list::VirtualList; use nostrdb::{Note, Transaction}; use notedeck::note::root_note_id_from_selected_id; -use notedeck::JobsCache; +use notedeck::JobsCacheOld; use notedeck::{NoteAction, NoteContext}; use notedeck_ui::note::NoteResponse; use notedeck_ui::{NoteOptions, NoteView}; @@ -16,7 +16,7 @@ pub struct ThreadView<'a, 'd> { note_options: NoteOptions, col: usize, note_context: &'a mut NoteContext<'d>, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, } impl<'a, 'd> ThreadView<'a, 'd> { @@ -26,7 +26,7 @@ impl<'a, 'd> ThreadView<'a, 'd> { selected_note_id: &'a [u8; 32], note_options: NoteOptions, note_context: &'a mut NoteContext<'d>, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, col: usize, ) -> Self { ThreadView { @@ -155,7 +155,7 @@ fn show_notes( thread_notes: &ThreadNotes, note_context: &mut NoteContext<'_>, flags: NoteOptions, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, txn: &Transaction, ) -> Option<NoteAction> { let mut action = None; @@ -326,7 +326,7 @@ impl<'a> ThreadNote<'a> { &self, note_context: &'a mut NoteContext<'_>, flags: NoteOptions, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, ui: &mut egui::Ui, ) -> NoteResponse { let inner = notedeck_ui::padding(8.0, ui, |ui| { diff --git a/crates/notedeck_columns/src/ui/timeline.rs b/crates/notedeck_columns/src/ui/timeline.rs @@ -6,7 +6,7 @@ use nostrdb::{Note, ProfileRecord, Transaction}; use notedeck::fonts::get_font_size; use notedeck::name::get_display_name; use notedeck::ui::is_narrow; -use notedeck::{tr_plural, JobsCache, Muted, NotedeckTextStyle}; +use notedeck::{tr_plural, JobsCacheOld, Muted, NotedeckTextStyle}; use notedeck_ui::app_images::{like_image_filled, repost_image}; use notedeck_ui::{ProfilePic, ProfilePreview}; use std::f32::consts::PI; @@ -30,7 +30,7 @@ pub struct TimelineView<'a, 'd> { timeline_cache: &'a mut TimelineCache, note_options: NoteOptions, note_context: &'a mut NoteContext<'d>, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, col: usize, scroll_to_top: bool, } @@ -42,7 +42,7 @@ impl<'a, 'd> TimelineView<'a, 'd> { timeline_cache: &'a mut TimelineCache, note_context: &'a mut NoteContext<'d>, note_options: NoteOptions, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, col: usize, ) -> Self { let scroll_to_top = false; @@ -93,7 +93,7 @@ fn timeline_ui( timeline_cache: &mut TimelineCache, mut note_options: NoteOptions, note_context: &mut NoteContext, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, col: usize, scroll_to_top: bool, ) -> BodyResponse<NoteAction> { @@ -378,7 +378,7 @@ pub struct TimelineTabView<'a, 'd> { note_options: NoteOptions, txn: &'a Transaction, note_context: &'a mut NoteContext<'d>, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, } impl<'a, 'd> TimelineTabView<'a, 'd> { @@ -388,7 +388,7 @@ impl<'a, 'd> TimelineTabView<'a, 'd> { note_options: NoteOptions, txn: &'a Transaction, note_context: &'a mut NoteContext<'d>, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, ) -> Self { Self { tab, @@ -676,7 +676,7 @@ fn render_note( ui: &mut egui::Ui, note_context: &mut NoteContext, note_options: NoteOptions, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, note: &Note, ) -> RenderEntryResponse { let mut action = None; @@ -699,7 +699,7 @@ fn render_reaction_cluster( ui: &mut egui::Ui, note_context: &mut NoteContext, note_options: NoteOptions, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, mute: &std::sync::Arc<Muted>, txn: &Transaction, underlying_note: &Note, @@ -742,7 +742,7 @@ fn render_composite_entry( ui: &mut egui::Ui, note_context: &mut NoteContext, mut note_options: NoteOptions, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, underlying_note: &nostrdb::Note<'_>, profiles_to_show: Vec<ProfileEntry>, composite_type: CompositeType, @@ -977,7 +977,7 @@ fn render_repost_cluster( ui: &mut egui::Ui, note_context: &mut NoteContext, note_options: NoteOptions, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, mute: &std::sync::Arc<Muted>, txn: &Transaction, underlying_note: &Note, diff --git a/crates/notedeck_dave/src/lib.rs b/crates/notedeck_dave/src/lib.rs @@ -8,7 +8,7 @@ use egui_wgpu::RenderState; use enostr::KeypairUnowned; use futures::StreamExt; use nostrdb::Transaction; -use notedeck::{AppAction, AppContext, AppResponse, JobsCache}; +use notedeck::{AppAction, AppContext, AppResponse, JobsCacheOld}; use std::collections::HashMap; use std::string::ToString; use std::sync::mpsc::{self, Receiver}; @@ -43,7 +43,7 @@ pub struct Dave { client: async_openai::Client<OpenAIConfig>, incoming_tokens: Option<Receiver<DaveApiResponse>>, model_config: ModelConfig, - jobs: JobsCache, + jobs: JobsCacheOld, } /// Calculate an anonymous user_id from a keypair @@ -108,7 +108,7 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr input, model_config, chat: vec![], - jobs: JobsCache::default(), + jobs: JobsCacheOld::default(), } } diff --git a/crates/notedeck_dave/src/ui/dave.rs b/crates/notedeck_dave/src/ui/dave.rs @@ -5,7 +5,7 @@ use crate::{ use egui::{Align, Key, KeyboardShortcut, Layout, Modifiers}; use nostrdb::{Ndb, Transaction}; use notedeck::{ - tr, Accounts, AppContext, Images, JobsCache, Localization, NoteAction, NoteContext, + tr, Accounts, AppContext, Images, JobsCacheOld, Localization, NoteAction, NoteContext, }; use notedeck_ui::{app_images, icons::search_icon, NoteOptions, ProfilePic}; @@ -89,7 +89,7 @@ impl<'a> DaveUi<'a> { pub fn ui( &mut self, app_ctx: &mut AppContext, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, ui: &mut egui::Ui, ) -> DaveResponse { let action = top_buttons_ui(app_ctx, ui); @@ -155,7 +155,7 @@ impl<'a> DaveUi<'a> { fn render_chat( &self, ctx: &mut AppContext, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, ui: &mut egui::Ui, ) -> Option<NoteAction> { let mut action: Option<NoteAction> = None; @@ -207,7 +207,7 @@ impl<'a> DaveUi<'a> { /// The ai has asked us to render some notes, so we do that here fn present_notes_ui( ctx: &mut AppContext, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, call: &PresentNotesCall, ui: &mut egui::Ui, ) -> Option<NoteAction> { @@ -272,7 +272,7 @@ impl<'a> DaveUi<'a> { fn tool_calls_ui( ctx: &mut AppContext, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, toolcalls: &[ToolCall], ui: &mut egui::Ui, ) -> Option<NoteAction> { diff --git a/crates/notedeck_ui/src/nip51_set.rs b/crates/notedeck_ui/src/nip51_set.rs @@ -4,8 +4,8 @@ use enostr::Pubkey; use hashbrown::{hash_map::RawEntryMut, HashMap}; use nostrdb::{Ndb, ProfileRecord, Transaction}; use notedeck::{ - fonts::get_font_size, get_profile_url, name::get_display_name, tr, Images, JobPool, JobsCache, - Localization, Nip51Set, Nip51SetCache, NotedeckTextStyle, + fonts::get_font_size, get_profile_url, name::get_display_name, tr, Images, JobPool, + JobsCacheOld, Localization, Nip51Set, Nip51SetCache, NotedeckTextStyle, }; use crate::{ @@ -20,7 +20,7 @@ pub struct Nip51SetWidget<'a> { images: &'a mut Images, loc: &'a mut Localization, job_pool: &'a mut JobPool, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, flags: Nip51SetWidgetFlags, } @@ -54,7 +54,7 @@ impl<'a> Nip51SetWidget<'a> { loc: &'a mut Localization, images: &'a mut Images, job_pool: &'a mut JobPool, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, ) -> Self { Self { state, @@ -158,7 +158,7 @@ fn render_pack( ndb: &Ndb, images: &mut Images, job_pool: &mut JobPool, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, loc: &mut Localization, image_trusted: bool, ) -> Option<Nip51SetWidgetAction> { diff --git a/crates/notedeck_ui/src/note/contents.rs b/crates/notedeck_ui/src/note/contents.rs @@ -7,7 +7,7 @@ use egui::{Color32, Hyperlink, Label, RichText}; use nostrdb::{BlockType, Mention, Note, NoteKey, Transaction}; use notedeck::Localization; use notedeck::{time_format, update_imeta_blurhashes, NoteCache, NoteContext, NotedeckTextStyle}; -use notedeck::{JobsCache, RenderableMedia}; +use notedeck::{JobsCacheOld, RenderableMedia}; use tracing::warn; pub struct NoteContents<'a, 'd> { @@ -16,7 +16,7 @@ pub struct NoteContents<'a, 'd> { note: &'a Note<'a>, options: NoteOptions, pub action: Option<NoteAction>, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, } impl<'a, 'd> NoteContents<'a, 'd> { @@ -26,7 +26,7 @@ impl<'a, 'd> NoteContents<'a, 'd> { txn: &'a Transaction, note: &'a Note, options: NoteOptions, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, ) -> Self { NoteContents { note_context, @@ -83,7 +83,7 @@ pub fn render_note_preview( id: &[u8; 32], parent: NoteKey, note_options: NoteOptions, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, ) -> NoteResponse { let note = if let Ok(note) = note_context.ndb.get_note_by_id(txn, id) { // TODO: support other preview kinds @@ -125,7 +125,7 @@ fn render_note_contents( txn: &Transaction, note: &Note, options: NoteOptions, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, ) -> NoteResponse { let response = render_undecorated_note_contents(ui, note_context, txn, note, options, jobs); @@ -169,7 +169,7 @@ fn render_undecorated_note_contents<'a>( txn: &Transaction, note: &'a Note, options: NoteOptions, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, ) -> NoteResponse { let note_key = note.key().expect("todo: implement non-db notes"); let selectable = options.contains(NoteOptions::SelectableText); diff --git a/crates/notedeck_ui/src/note/media.rs b/crates/notedeck_ui/src/note/media.rs @@ -7,7 +7,7 @@ use egui::{ }; use notedeck::{ compute_blurhash, fonts::get_font_size, show_one_error_message, tr, BlurhashParams, - GifStateMap, Images, Job, JobId, JobParams, JobPool, JobState, JobsCache, Localization, + GifStateMap, Images, Job, JobIdOld, JobParams, JobPool, JobState, JobsCacheOld, Localization, MediaAction, MediaCacheType, NotedeckTextStyle, ObfuscationType, PointDimensions, RenderableMedia, TexturedImage, TexturesCache, }; @@ -31,7 +31,7 @@ pub fn image_carousel( ui: &mut egui::Ui, img_cache: &mut Images, job_pool: &mut JobPool, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, medias: &[RenderableMedia], carousel_id: egui::Id, i18n: &mut Localization, @@ -120,7 +120,7 @@ pub fn render_media( ui: &mut egui::Ui, img_cache: &mut Images, job_pool: &mut JobPool, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, media: &RenderableMedia, trusted_media: bool, i18n: &mut Localization, @@ -242,7 +242,7 @@ impl MediaUIAction { pub fn get_content_media_render_state<'a>( ui: &mut egui::Ui, job_pool: &'a mut JobPool, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, media_trusted: bool, size: Vec2, cache: &'a mut TexturesCache, @@ -302,7 +302,7 @@ fn get_obfuscated<'a>( url: &str, obfuscation_type: &'a ObfuscationType, job_pool: &'a mut JobPool, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, size: Vec2, ) -> ObfuscatedTexture<'a> { let ObfuscationType::Blurhash(renderable_blur) = obfuscation_type else { @@ -324,7 +324,7 @@ fn get_obfuscated<'a>( let job_state = jobs.get_or_insert_with( job_pool, - &JobId::Blurhash(url), + &JobIdOld::Blurhash(url), Some(JobParams::Blurhash(params)), move |params| compute_blurhash(params, pixel_sizes), ); diff --git a/crates/notedeck_ui/src/note/mod.rs b/crates/notedeck_ui/src/note/mod.rs @@ -15,7 +15,7 @@ use notedeck::ui::is_narrow; use notedeck::Accounts; use notedeck::GlobalWallet; use notedeck::Images; -use notedeck::JobsCache; +use notedeck::JobsCacheOld; use notedeck::Localization; use notedeck::MediaAction; pub use options::NoteOptions; @@ -35,7 +35,7 @@ pub struct NoteView<'a, 'd> { parent: Option<NoteKey>, note: &'a nostrdb::Note<'a>, flags: NoteOptions, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, } pub struct NoteResponse { @@ -83,7 +83,7 @@ impl<'a, 'd> NoteView<'a, 'd> { note_context: &'a mut NoteContext<'d>, note: &'a nostrdb::Note<'a>, flags: NoteOptions, - jobs: &'a mut JobsCache, + jobs: &'a mut JobsCacheOld, ) -> Self { let parent: Option<NoteKey> = None; diff --git a/crates/notedeck_ui/src/note/reply_description.rs b/crates/notedeck_ui/src/note/reply_description.rs @@ -3,7 +3,7 @@ use nostrdb::{NoteReply, Transaction}; use super::NoteOptions; use crate::{note::NoteView, Mention}; -use notedeck::{tr, JobsCache, NoteAction, NoteContext}; +use notedeck::{tr, JobsCacheOld, NoteAction, NoteContext}; // Rich text segment types for internationalized rendering #[derive(Debug, Clone)] @@ -106,7 +106,7 @@ fn render_text_segments( txn: &Transaction, note_context: &mut NoteContext, note_options: NoteOptions, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, size: f32, selectable: bool, ) -> Option<NoteAction> { @@ -219,7 +219,7 @@ pub fn reply_desc( note_reply: &NoteReply, note_context: &mut NoteContext, note_options: NoteOptions, - jobs: &mut JobsCache, + jobs: &mut JobsCacheOld, ) -> Option<NoteAction> { let size = 10.0; let selectable = false;