This commit is contained in:
2026-09-04 08:16:05 +07:00
parent 212f35d6bb
commit 17de4f6376
43 changed files with 376 additions and 721 deletions
+6 -5
View File
@@ -63,6 +63,7 @@ impl Profile {
/// Message from the fetch task to the main thread.
enum Dispatch {
/// A batched sync finished.
///
/// Re-read seen profiles from the database.
Synced,
}
@@ -71,8 +72,8 @@ enum Dispatch {
const BATCH_TIMEOUT: Duration = Duration::from_millis(500);
/// Global profile cache.
///
/// Profiles are fetched in batches and kept as plain data.
/// The whole store notifies on change.
pub struct ProfileStore {
profiles: HashMap<PublicKey, Profile>,
/// Public keys requested this session, main thread only.
@@ -114,7 +115,6 @@ impl ProfileStore {
});
// Fetch requests are queued on a channel.
// A background task syncs them in batches.
let client = backend.read(cx).client();
let (sender, receiver) = flume::unbounded::<PublicKey>();
let (dispatch_tx, dispatch_rx) = flume::unbounded::<Dispatch>();
@@ -146,8 +146,8 @@ impl ProfileStore {
}
/// Get a profile.
/// Returns a placeholder with default metadata.
/// Queues a fetch when the profile is not cached yet.
///
/// Returns a placeholder with default metadata. Queues a fetch when the profile is not cached yet.
pub fn get(&self, public_key: &PublicKey) -> Profile {
if let Some(profile) = self.profiles.get(public_key) {
return profile.clone();
@@ -237,6 +237,7 @@ impl ProfileStore {
}
/// Re-read the latest metadata of every requested author from the local database.
///
/// Used after a sync, which produces no NostrUpdate events.
fn apply_seen(&mut self, cx: &mut Context<Self>) {
let authors: Vec<PublicKey> = self.seen.borrow().iter().copied().collect();
@@ -292,7 +293,7 @@ impl ProfileStore {
}
/// Sync metadata for requested authors in batches, debounced to collect requests.
/// Runs on a background thread.
///
/// Results are dispatched to the main thread, which re-reads the database.
async fn handle_requests(
client: &Client,