From 17a0b3430934fbb8370066ee9dc3506102c5b3f6 Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Sat, 27 Apr 2024 20:02:18 -0700 Subject: [PATCH] remove version checker This reverts commit b8c164dc6027844d665158dc8906dd5c89f9238b. --- src/config/mod.rs | 2 - src/database/key_value/globals.rs | 18 --------- src/database/mod.rs | 62 +------------------------------ src/service/globals/data.rs | 2 - src/service/globals/mod.rs | 14 ------- 5 files changed, 2 insertions(+), 96 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index fb1e2f31..85df6e6a 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -27,8 +27,6 @@ pub struct Config { pub db_cache_capacity_mb: f64, #[serde(default = "true_fn")] pub enable_lightning_bolt: bool, - #[serde(default = "true_fn")] - pub allow_check_for_updates: bool, #[serde(default = "default_conduit_cache_capacity_modifier")] pub conduit_cache_capacity_modifier: f64, #[serde(default = "default_rocksdb_max_open_files")] diff --git a/src/database/key_value/globals.rs b/src/database/key_value/globals.rs index 2851ce53..aa13e64f 100644 --- a/src/database/key_value/globals.rs +++ b/src/database/key_value/globals.rs @@ -12,7 +12,6 @@ use ruma::{ use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; pub const COUNTER: &[u8] = b"c"; -pub const LAST_CHECK_FOR_UPDATES_COUNT: &[u8] = b"u"; #[async_trait] impl service::globals::Data for KeyValueDatabase { @@ -28,23 +27,6 @@ impl service::globals::Data for KeyValueDatabase { }) } - fn last_check_for_updates_id(&self) -> Result { - self.global - .get(LAST_CHECK_FOR_UPDATES_COUNT)? - .map_or(Ok(0_u64), |bytes| { - utils::u64_from_bytes(&bytes).map_err(|_| { - Error::bad_database("last check for updates count has invalid bytes.") - }) - }) - } - - fn update_check_for_updates_id(&self, id: u64) -> Result<()> { - self.global - .insert(LAST_CHECK_FOR_UPDATES_COUNT, &id.to_be_bytes())?; - - Ok(()) - } - async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { let userid_bytes = user_id.as_bytes().to_vec(); let mut userid_prefix = userid_bytes.clone(); diff --git a/src/database/mod.rs b/src/database/mod.rs index 41da857c..7008d56f 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -19,7 +19,6 @@ use ruma::{ CanonicalJsonValue, EventId, OwnedDeviceId, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId, }; -use serde::Deserialize; use std::{ collections::{BTreeMap, HashMap, HashSet}, fs::{self, remove_dir_all}, @@ -27,9 +26,7 @@ use std::{ mem::size_of, path::Path, sync::{Arc, Mutex, RwLock}, - time::Duration, }; -use tokio::time::interval; use tracing::{debug, error, info, warn}; @@ -986,9 +983,6 @@ impl KeyValueDatabase { services().sending.start_handler(); Self::start_cleanup_task().await; - if services().globals.allow_check_for_updates() { - Self::start_check_for_updates_task(); - } Ok(()) } @@ -1004,62 +998,10 @@ impl KeyValueDatabase { res } - #[tracing::instrument] - pub fn start_check_for_updates_task() { - tokio::spawn(async move { - let timer_interval = Duration::from_secs(60 * 60); - let mut i = interval(timer_interval); - loop { - i.tick().await; - let _ = Self::try_handle_updates().await; - } - }); - } - - async fn try_handle_updates() -> Result<()> { - let response = services() - .globals - .default_client() - .get("https://conduit.rs/check-for-updates/stable") - .send() - .await?; - - #[derive(Deserialize)] - struct CheckForUpdatesResponseEntry { - id: u64, - date: String, - message: String, - } - #[derive(Deserialize)] - struct CheckForUpdatesResponse { - updates: Vec, - } - - let response = serde_json::from_str::(&response.text().await?) - .map_err(|_| Error::BadServerResponse("Bad version check response"))?; - - let mut last_update_id = services().globals.last_check_for_updates_id()?; - for update in response.updates { - last_update_id = last_update_id.max(update.id); - if update.id > services().globals.last_check_for_updates_id()? { - println!("{}", update.message); - services() - .admin - .send_message(RoomMessageEventContent::text_plain(format!( - "@room: The following is a message from the Conduit developers. It was sent on '{}':\n\n{}", - update.date, update.message - ))) - } - } - services() - .globals - .update_check_for_updates_id(last_update_id)?; - - Ok(()) - } - #[tracing::instrument] pub async fn start_cleanup_task() { + use tokio::time::interval; + #[cfg(unix)] use tokio::signal::unix::{signal, SignalKind}; diff --git a/src/service/globals/data.rs b/src/service/globals/data.rs index 8a66751b..171b3fec 100644 --- a/src/service/globals/data.rs +++ b/src/service/globals/data.rs @@ -13,8 +13,6 @@ use crate::Result; pub trait Data: Send + Sync { fn next_count(&self) -> Result; fn current_count(&self) -> Result; - fn last_check_for_updates_id(&self) -> Result; - fn update_check_for_updates_id(&self, id: u64) -> Result<()>; async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()>; fn cleanup(&self) -> Result<()>; fn memory_usage(&self) -> String; diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index 798c725a..3088ac9b 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -255,16 +255,6 @@ impl Service { self.db.current_count() } - #[tracing::instrument(skip(self))] - pub fn last_check_for_updates_id(&self) -> Result { - self.db.last_check_for_updates_id() - } - - #[tracing::instrument(skip(self))] - pub fn update_check_for_updates_id(&self, id: u64) -> Result<()> { - self.db.update_check_for_updates_id(id) - } - pub async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { self.db.watch(user_id, device_id).await } @@ -313,10 +303,6 @@ impl Service { self.config.enable_lightning_bolt } - pub fn allow_check_for_updates(&self) -> bool { - self.config.allow_check_for_updates - } - pub fn trusted_servers(&self) -> &[OwnedServerName] { &self.config.trusted_servers }