Stop using GLOBALS.settings, use storage directly instead

This commit is contained in:
Mike Dilger 2023-08-19 10:22:48 +12:00
parent b6c0a6e257
commit 2bb6182c07
9 changed files with 20 additions and 53 deletions

View File

@ -37,7 +37,6 @@ pub enum ToOverlordMessage {
ClearAllUsageOnRelay(RelayUrl),
Repost(Id),
RankRelay(RelayUrl, u8),
SaveSettings,
Search(String),
SetActivePerson(PublicKey),
AdjustRelayUsageBit(RelayUrl, u64, bool),

View File

@ -59,9 +59,9 @@ impl Delegation {
}
pub async fn save_through_settings(&self) -> Result<(), Error> {
GLOBALS.settings.write().delegatee_tag = self.get_delegatee_tag_as_str();
let settings = GLOBALS.settings.read();
settings.save()?;
GLOBALS
.storage
.write_setting_delegatee_tag(&self.get_delegatee_tag_as_str(), None)?;
Ok(())
}
}

View File

@ -6,7 +6,6 @@ use crate::media::Media;
use crate::people::{People, Person};
use crate::relay::Relay;
use crate::relay_picker_hooks::Hooks;
use crate::settings::Settings;
use crate::signer::Signer;
use crate::status::StatusQueue;
use crate::storage::Storage;
@ -59,9 +58,6 @@ pub struct Globals {
/// waited for by the overlord)
pub shutting_down: AtomicBool,
/// Settings
pub settings: PRwLock<Settings>,
/// Signer
pub signer: Signer,
@ -144,7 +140,6 @@ lazy_static! {
connected_relays: DashMap::new(),
relay_picker: Default::default(),
shutting_down: AtomicBool::new(false),
settings: PRwLock::new(Settings::default()),
signer: Signer::default(),
dismissed: RwLock::new(Vec::new()),
feed: Feed::new(),

View File

@ -52,7 +52,6 @@ mod ui;
use crate::comms::ToOverlordMessage;
use crate::error::Error;
use crate::globals::GLOBALS;
use crate::settings::Settings;
use std::ops::DerefMut;
use std::{env, thread};
use tracing_subscriber::filter::{EnvFilter, LevelFilter};
@ -83,10 +82,6 @@ fn main() -> Result<(), Error> {
// Initialize storage
GLOBALS.storage.init()?;
// Load settings
let settings = Settings::load();
*GLOBALS.settings.write() = settings;
// We create and enter the runtime on the main thread so that
// non-async code can have a runtime context within which to spawn
// async tasks.

View File

@ -434,13 +434,8 @@ impl Minion {
followed_pubkeys: Vec<PublicKey>,
) -> Result<(), Error> {
let mut filters: Vec<Filter> = Vec::new();
let (overlap, feed_chunk) = {
let settings = GLOBALS.settings.read().clone();
(
Duration::from_secs(settings.overlap),
Duration::from_secs(settings.feed_chunk),
)
};
let overlap = Duration::from_secs(GLOBALS.storage.read_setting_overlap());
let feed_chunk = Duration::from_secs(GLOBALS.storage.read_setting_feed_chunk());
tracing::debug!(
"Following {} people at {}",
@ -568,13 +563,8 @@ impl Minion {
// (and any other relay for the time being until nip65 is in widespread use)
async fn subscribe_mentions(&mut self, job_id: u64) -> Result<(), Error> {
let mut filters: Vec<Filter> = Vec::new();
let (overlap, replies_chunk) = {
let settings = GLOBALS.settings.read().clone();
(
Duration::from_secs(settings.overlap),
Duration::from_secs(settings.replies_chunk),
)
};
let overlap = Duration::from_secs(GLOBALS.storage.read_setting_overlap());
let replies_chunk = Duration::from_secs(GLOBALS.storage.read_setting_replies_chunk());
// Compute how far to look back
let replies_since = {
@ -697,7 +687,7 @@ impl Minion {
..Default::default()
}];
// let feed_chunk = GLOBALS.settings.read().await.feed_chunk;
// let feed_chunk = GLOBALS.storage.read_setting_feed_chunk();
// Don't do this anymore. It's low value and we can't compute how far back to look
// until after we get their 25th oldest post.
@ -811,11 +801,9 @@ impl Minion {
// Compute how far to look back
let (feed_since, special_since) = {
// Get related settings
let (overlap, feed_chunk) = {
let settings = GLOBALS.settings.read().await.clone();
(settings.overlap, settings.feed_chunk)
};
// Get related settings
let overlap = Duration::from_secs(GLOBALS.storage.read_setting_overlap());
let feed_chunk = Duration::from_secs(GLOBALS.storage.read_setting_feed_chunk());
/*
// Find the oldest 'last_fetched' among the 'person_relay' table.

View File

@ -725,11 +725,6 @@ impl Overlord {
ToOverlordMessage::Repost(id) => {
self.repost(id).await?;
}
ToOverlordMessage::SaveSettings => {
let settings = GLOBALS.settings.read().clone();
settings.save()?;
tracing::debug!("Settings saved.");
}
ToOverlordMessage::Search(text) => {
Overlord::search(text).await?;
}
@ -756,9 +751,9 @@ impl Overlord {
// Update public key from private key
let public_key = GLOBALS.signer.public_key().unwrap();
GLOBALS.settings.write().public_key = Some(public_key);
let settings = GLOBALS.settings.read().clone();
settings.save()?;
GLOBALS
.storage
.write_setting_public_key(&Some(public_key), None)?;
}
ToOverlordMessage::UpdateFollowing(merge) => {
self.update_following(merge).await?;

View File

@ -27,9 +27,9 @@ impl Signer {
}
pub async fn save_through_settings(&self) -> Result<(), Error> {
GLOBALS.settings.write().public_key = *self.public.read();
let settings = GLOBALS.settings.read().clone();
settings.save()?;
GLOBALS
.storage
.write_setting_public_key(&self.public.read(), None)?;
let epk = self.encrypted.read().clone();
GLOBALS.storage.write_encrypted_private_key(&epk, None)?;

View File

@ -290,7 +290,7 @@ impl Drop for GossipUi {
impl GossipUi {
fn new(cctx: &eframe::CreationContext<'_>) -> Self {
let mut settings = GLOBALS.settings.read().clone();
let mut settings = Settings::load();
if let Some(dpi) = settings.override_dpi {
let ppt: f32 = dpi as f32 / 72.0;

View File

@ -1,7 +1,5 @@
use crate::comms::ToOverlordMessage;
use crate::settings::Settings;
use crate::ui::{GossipUi, SettingsTab};
use crate::GLOBALS;
use eframe::egui;
use egui::{Align, Context, Layout, ScrollArea, Ui, Vec2};
@ -19,7 +17,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
let stored_settings = Settings::load();
if stored_settings != app.settings {
if ui.button("REVERT CHANGES").clicked() {
app.settings = GLOBALS.settings.read().clone();
app.settings = Settings::load();
// Fully revert any DPI changes
match app.settings.override_dpi {
@ -51,10 +49,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
}
// Copy local settings to global settings
*GLOBALS.settings.write() = app.settings.clone();
// Tell the overlord to save them
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::SaveSettings);
let _ = app.settings.save();
}
}
});