chore: fix some performance issues #6
919
Cargo.lock
generated
919
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -331,7 +331,11 @@ impl Sidebar {
|
|||||||
|
|
||||||
// Create a new room and emit it
|
// Create a new room and emit it
|
||||||
async_chat.update_in(cx, |this, _window, cx| {
|
async_chat.update_in(cx, |this, _window, cx| {
|
||||||
let room = cx.new(|_| Room::new(public_key, receivers).kind(RoomKind::Ongoing));
|
let room = cx.new(|_| {
|
||||||
|
Room::new(public_key, receivers)
|
||||||
|
.organize(&public_key)
|
||||||
|
.kind(RoomKind::Ongoing)
|
||||||
|
});
|
||||||
this.emit_room(&room, cx);
|
this.emit_room(&room, cx);
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ edition.workspace = true
|
|||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
state = { path = "../state" }
|
common = { path = "../common" }
|
||||||
|
|
||||||
nostr-sdk.workspace = true
|
nostr-sdk.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
|
smol.workspace = true
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use anyhow::{anyhow, Context as AnyhowContext, Error};
|
use anyhow::{anyhow, Error};
|
||||||
|
use common::config_dir;
|
||||||
use gpui::{App, AppContext, Context, Entity, Global, Subscription, Task};
|
use gpui::{App, AppContext, Context, Entity, Global, Subscription, Task};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
use state::NostrRegistry;
|
|
||||||
|
|
||||||
const SETTINGS_IDENTIFIER: &str = "coop:settings";
|
|
||||||
|
|
||||||
pub fn init(cx: &mut App) {
|
pub fn init(cx: &mut App) {
|
||||||
AppSettings::set_global(cx.new(AppSettings::new), cx)
|
AppSettings::set_global(cx.new(AppSettings::new), cx)
|
||||||
@@ -133,7 +131,6 @@ impl AppSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn new(cx: &mut Context<Self>) -> Self {
|
fn new(cx: &mut Context<Self>) -> Self {
|
||||||
let nostr = NostrRegistry::global(cx);
|
|
||||||
let mut subscriptions = smallvec![];
|
let mut subscriptions = smallvec![];
|
||||||
|
|
||||||
subscriptions.push(
|
subscriptions.push(
|
||||||
@@ -143,12 +140,13 @@ impl AppSettings {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
subscriptions.push(
|
cx.defer(|cx| {
|
||||||
// Observe and automatically save settings on changes
|
let settings = AppSettings::global(cx);
|
||||||
cx.observe(&nostr, |this, _state, cx| {
|
|
||||||
|
settings.update(cx, |this, cx| {
|
||||||
this.load(cx);
|
this.load(cx);
|
||||||
}),
|
});
|
||||||
);
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
values: Settings::default(),
|
values: Settings::default(),
|
||||||
@@ -164,21 +162,11 @@ impl AppSettings {
|
|||||||
|
|
||||||
/// Load settings
|
/// Load settings
|
||||||
fn load(&mut self, cx: &mut Context<Self>) {
|
fn load(&mut self, cx: &mut Context<Self>) {
|
||||||
let nostr = NostrRegistry::global(cx);
|
|
||||||
let client = nostr.read(cx).client();
|
|
||||||
|
|
||||||
let task: Task<Result<Settings, Error>> = cx.background_spawn(async move {
|
let task: Task<Result<Settings, Error>> = cx.background_spawn(async move {
|
||||||
let signer = client.signer().context("Signer not found")?;
|
let path = config_dir().join(".settings");
|
||||||
let public_key = signer.get_public_key().await?;
|
|
||||||
|
|
||||||
let filter = Filter::new()
|
if let Ok(content) = smol::fs::read_to_string(&path).await {
|
||||||
.kind(Kind::ApplicationSpecificData)
|
Ok(serde_json::from_str(&content)?)
|
||||||
.identifier(SETTINGS_IDENTIFIER)
|
|
||||||
.author(public_key)
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if let Some(event) = client.database().query(filter).await?.last_owned() {
|
|
||||||
Ok(serde_json::from_str(&event.content)?)
|
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow!("Not found"))
|
Err(anyhow!("Not found"))
|
||||||
}
|
}
|
||||||
@@ -198,23 +186,14 @@ impl AppSettings {
|
|||||||
|
|
||||||
/// Save settings
|
/// Save settings
|
||||||
pub fn save(&mut self, cx: &mut Context<Self>) {
|
pub fn save(&mut self, cx: &mut Context<Self>) {
|
||||||
let nostr = NostrRegistry::global(cx);
|
|
||||||
let client = nostr.read(cx).client();
|
|
||||||
let settings = self.values.clone();
|
let settings = self.values.clone();
|
||||||
|
|
||||||
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
||||||
let signer = client.signer().context("Signer not found")?;
|
let path = config_dir().join(".settings");
|
||||||
let public_key = signer.get_public_key().await?;
|
|
||||||
let content = serde_json::to_string(&settings)?;
|
let content = serde_json::to_string(&settings)?;
|
||||||
|
|
||||||
let event = EventBuilder::new(Kind::ApplicationSpecificData, content)
|
// Write settings to file
|
||||||
.tag(Tag::identifier(SETTINGS_IDENTIFIER))
|
smol::fs::write(&path, content).await?;
|
||||||
.build(public_key)
|
|
||||||
.sign(&Keys::generate())
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
// Save event to the local database only
|
|
||||||
client.database().save_event(&event).await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ pub const APP_ID: &str = "su.reya.coop";
|
|||||||
pub const KEYRING: &str = "Coop Safe Storage";
|
pub const KEYRING: &str = "Coop Safe Storage";
|
||||||
|
|
||||||
/// Default timeout for subscription
|
/// Default timeout for subscription
|
||||||
pub const TIMEOUT: u64 = 3;
|
pub const TIMEOUT: u64 = 2;
|
||||||
|
|
||||||
/// Default delay for searching
|
/// Default delay for searching
|
||||||
pub const FIND_DELAY: u64 = 600;
|
pub const FIND_DELAY: u64 = 600;
|
||||||
|
|||||||
@@ -1009,8 +1009,7 @@ impl InputState {
|
|||||||
let left_part = self.text.slice(0..offset).to_string();
|
let left_part = self.text.slice(0..offset).to_string();
|
||||||
|
|
||||||
UnicodeSegmentation::split_word_bound_indices(left_part.as_str())
|
UnicodeSegmentation::split_word_bound_indices(left_part.as_str())
|
||||||
.filter(|(_, s)| !s.trim_start().is_empty())
|
.rfind(|(_, s)| !s.trim_start().is_empty())
|
||||||
.next_back()
|
|
||||||
.map(|(i, _)| i)
|
.map(|(i, _)| i)
|
||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1094,13 +1094,10 @@ impl Render for PopupMenu {
|
|||||||
self.update_submenu_menu_anchor(window);
|
self.update_submenu_menu_anchor(window);
|
||||||
|
|
||||||
let max_width = self.max_width();
|
let max_width = self.max_width();
|
||||||
let max_height = self.max_height.map_or_else(
|
let max_height = self.max_height.unwrap_or_else(|| {
|
||||||
|| {
|
|
||||||
let window_half_height = window.window_bounds().get_bounds().size.height * 0.5;
|
let window_half_height = window.window_bounds().get_bounds().size.height * 0.5;
|
||||||
window_half_height.min(px(450.))
|
window_half_height.min(px(450.))
|
||||||
},
|
});
|
||||||
|height| height,
|
|
||||||
);
|
|
||||||
|
|
||||||
let view = cx.entity().clone();
|
let view = cx.entity().clone();
|
||||||
let items_count = self.menu_items.len();
|
let items_count = self.menu_items.len();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "1.91"
|
channel = "1.92"
|
||||||
profile = "minimal"
|
profile = "minimal"
|
||||||
components = ["rustfmt", "clippy"]
|
components = ["rustfmt", "clippy"]
|
||||||
targets = [
|
targets = [
|
||||||
|
|||||||
Reference in New Issue
Block a user