summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/data.rs8
-rw-r--r--src/data/effective.rs8
-rw-r--r--src/data/effective/tests.rs12
-rw-r--r--src/data/managers.rs103
-rw-r--r--src/data/sources/defaults.rs12
5 files changed, 36 insertions, 107 deletions
diff --git a/src/data.rs b/src/data.rs
index 75ce565..abce42e 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -22,7 +22,6 @@
 
 use std::error;
 use std::hash::Hash;
-use std::time::Duration;
 
 pub mod effective;
 pub mod kinds;
@@ -35,10 +34,7 @@ mod tests;
 /// A source of data.
 pub trait DataSourceBase: std::fmt::Display {
     /// Refreshes the data associated with this source.
-    fn update(&mut self) -> (
-        Option<Duration>,
-        Result<(), Box<dyn error::Error + Send + Sync + 'static>>,
-    );
+    fn update(&mut self) -> Update;
 
     /// Returns whether this data source contains any (valid) data.
     ///
@@ -93,8 +89,6 @@ pub trait OverridableKind: Kind {
 /// Stats about an update.
 #[derive(Default)]
 pub struct Update {
-    /// Time until next refresh, if known.
-    pub refresh: Option<Duration>,
     /// Errors collected in an update.
     pub errors: Vec<Box<dyn error::Error + Send + Sync + 'static>>,
 }
diff --git a/src/data/effective.rs b/src/data/effective.rs
index 54b524f..bcfff6e 100644
--- a/src/data/effective.rs
+++ b/src/data/effective.rs
@@ -26,8 +26,6 @@
 
 use std::collections::BTreeSet;
 use std::collections::HashSet;
-use std::error;
-use std::time::Duration;
 
 use impl_trait::impl_trait;
 
@@ -35,6 +33,7 @@ use super::DataSource;
 use super::DataSourceBase;
 use super::Kind;
 use super::OverridableKind;
+use super::Update;
 
 #[cfg(test)]
 mod tests;
@@ -115,10 +114,7 @@ impl_trait! {
 
         /// Forwards to the inner [`DataSourceBase`].
         impl trait DataSourceBase {
-            fn update(&mut self) -> (
-                Option<Duration>,
-                Result<(), Box<dyn error::Error + Send + Sync + 'static>>,
-            ) {
+            fn update(&mut self) -> Update {
                 self.0.update()
             }
 
diff --git a/src/data/effective/tests.rs b/src/data/effective/tests.rs
index dab503f..9d0a21f 100644
--- a/src/data/effective/tests.rs
+++ b/src/data/effective/tests.rs
@@ -17,8 +17,6 @@
 //! Unit tests for the effective module.
 
 use std::collections::BTreeSet;
-use std::error;
-use std::time::Duration;
 
 use impl_trait::impl_trait;
 use url::Url;
@@ -26,6 +24,7 @@ use url::Url;
 use crate::data::{
     DataSource,
     DataSourceBase,
+    Update,
 };
 use crate::data::kinds::{
     InstanceBaseUrl,
@@ -40,13 +39,10 @@ struct EffectiveTester;
 
 impl_trait! {
     impl EffectiveTester {
-        /// Always updates successfully, with an unknown refresh interval.
+        /// Always updates with no stats.
         impl trait DataSourceBase {
-            fn update(&mut self) -> (
-                Option<Duration>,
-                Result<(), Box<dyn error::Error + Send + Sync + 'static>>,
-            ) {
-                (None, Ok(()))
+            fn update(&mut self) -> Update {
+                Update::default()
             }
 
             fn exists(&self) -> bool {
diff --git a/src/data/managers.rs b/src/data/managers.rs
index 9a82a8e..7b34f80 100644
--- a/src/data/managers.rs
+++ b/src/data/managers.rs
@@ -23,7 +23,6 @@ use std::collections::BTreeSet;
 use std::error;
 use std::fmt;
 use std::sync::Arc;
-use std::time::Duration;
 
 use impl_trait::impl_trait;
 use qcell::{QCell, QCellOwner};
@@ -35,6 +34,7 @@ use super::effective::EffectiveDataSource;
 use super::effective::EffectiveKind;
 use super::kinds::{InstanceTitle, InstanceBaseUrl, RepoListUrl, ProjectFork};
 use super::sources::DefaultsDataSource;
+use super::Update;
 
 /// A wrapper around multiple [`DataSource`]s of [`ProjectFork`]s.
 ///
@@ -44,7 +44,6 @@ use super::sources::DefaultsDataSource;
 #[derive(Default)]
 pub struct RepoListManager {
     repos: Vec<Box<dyn DataSource<EffectiveKind<ProjectFork>> + Send + Sync>>,
-    durations: Vec<Option<Duration>>,
     valid: usize,
 }
 
@@ -63,7 +62,6 @@ pub struct RepoListManager {
 pub struct ConfigManager {
     owner: QCellOwner,
     resources: Vec<Resource>,
-    durations: Vec<Option<Duration>>,
     // add_source can be called after update.
     valid: usize,
 }
@@ -153,14 +151,9 @@ impl_trait! {
         }
 
         impl trait DataSourceBase {
-            /// Updates the contained `DataSource`s, and returns the shortest
-            /// duration for the next update.
+            /// Updates the contained `DataSource`s, and returns any relevant
+            /// update stats.
             /// 
-            /// # Errors
-            ///
-            /// Returns an error if any `DataSource` returns an error. Always
-            /// updates all `DataSource`s.
-            ///
             /// # Examples
             ///
             /// ```
@@ -170,39 +163,19 @@ impl_trait! {
             ///
             /// let mut repos = RepoListManager::default();
             /// repos.add_source(DefaultsDataSource);
-            /// let (duration, result) = repos.update();
-            /// # assert!(duration.is_none());
-            /// # assert!(result.is_ok());
+            /// let update = repos.update();
+            /// # assert!(update.errors.is_empty());
             /// ```
-            fn update(&mut self) -> (
-                Option<Duration>,
-                Result<(), Box<dyn error::Error + Send + Sync + 'static>>,
-            ) {
-                let mut results = Vec::with_capacity(self.repos.len());
-                let mut ok = true;
-                self.durations.resize(self.repos.len(), None);
-                Iterator::zip(
-                    self.repos.iter_mut(),
-                    self.durations.iter_mut(),
-                ).for_each(|e| {
-                    if !matches!(*e.1, Some(d) if d.is_zero()) {
-                        results.push(Ok(()));
-                        return;
-                    }
-                    let (duration, result) = e.0.update();
-                    *e.1 = duration;
-                    ok &= result.is_ok();
-                    results.push(result);
+            fn update(&mut self) -> Update {
+                let mut errors = Vec::new();
+                self.repos.iter_mut().for_each(|e| {
+                    let ret = e.update();
+                    errors.extend(ret.errors);
                 });
-                let try_min = self.durations.iter().flatten().min().copied();
-                let min = try_min.unwrap_or(Duration::ZERO);
-                for duration in self.durations.iter_mut().flatten() {
-                    *duration -= min;
+                self.valid = self.repos.len();
+                Update {
+                    errors: errors,
                 }
-                self.valid = results.len();
-                (try_min, ok.then(|| ()).ok_or_else(|| {
-                    Box::new(MultiResult { results }) as _
-                }))
             }
 
             /// Returns whether this data source contains any (valid) data.
@@ -304,14 +277,9 @@ impl_trait! {
         }
 
         impl trait DataSourceBase {
-            /// Updates the contained `DataSource`s, and returns the shortest
-            /// duration for the next update.
+            /// Updates the contained `DataSource`s, and returns any relevant
+            /// update stats.
             /// 
-            /// # Errors
-            ///
-            /// Returns an error if any `DataSource` returns an error. Always
-            /// updates all `DataSource`s.
-            ///
             /// # Examples
             ///
             /// ```
@@ -320,41 +288,20 @@ impl_trait! {
             ///
             /// let mut cm = ConfigManager::default();
             /// cm.add_defaults();
-            /// let (duration, result) = cm.update();
-            /// # assert!(duration.is_none());
-            /// # assert!(result.is_ok());
+            /// let update = cm.update();
+            /// # assert!(update.errors.is_empty());
             /// ```
-            fn update(&mut self) -> (
-                Option<Duration>,
-                Result<(), Box<dyn error::Error + Send + Sync + 'static>>,
-            ) {
+            fn update(&mut self) -> Update {
                 let owner = &mut self.owner;
-                let mut results = Vec::with_capacity(self.resources.len());
-                let mut ok = true;
-                self.durations.resize(self.resources.len(), None);
-                Iterator::zip(
-                    self.resources.iter(),
-                    self.durations.iter_mut(),
-                ).for_each(|e| {
-                    if !matches!(*e.1, Some(d) if d.is_zero()) {
-                        results.push(Ok(()));
-                        return;
-                    }
-                    let ret = owner.rw(&*e.0.base).update();
-                    let (duration, result) = ret;
-                    *e.1 = duration;
-                    ok &= result.is_ok();
-                    results.push(result);
+                let mut errors = Vec::new();
+                self.resources.iter().for_each(|e| {
+                    let ret = owner.rw(&*e.base).update();
+                    errors.extend(ret.errors);
                 });
-                let try_min = self.durations.iter().flatten().min().copied();
-                let min = try_min.unwrap_or(Duration::ZERO);
-                for duration in self.durations.iter_mut().flatten() {
-                    *duration -= min;
+                self.valid = self.resources.len();
+                Update {
+                    errors: errors,
                 }
-                self.valid = results.len();
-                (try_min, ok.then(|| ()).ok_or_else(|| {
-                    Box::new(MultiResult { results }) as _
-                }))
             }
 
             /// Returns whether this data source contains any (valid) data.
diff --git a/src/data/sources/defaults.rs b/src/data/sources/defaults.rs
index e8ffa33..7db9e48 100644
--- a/src/data/sources/defaults.rs
+++ b/src/data/sources/defaults.rs
@@ -17,8 +17,6 @@
 //! Data source for compile-time defaults.
 
 use std::collections::BTreeSet;
-use std::error;
-use std::time::Duration;
 
 use impl_trait::impl_trait;
 
@@ -31,6 +29,7 @@ use super::super::kinds::{
     ProjectFork,
     RepoListUrl,
 };
+use super::super::Update;
 
 /// Data source that provides compile-time defaults.
 ///
@@ -49,13 +48,10 @@ pub struct DefaultsDataSource;
 
 impl_trait! {
     impl DefaultsDataSource {
-        /// Always updates successfully, with an unknown refresh interval.
+        /// Always updates with no stats.
         impl trait DataSourceBase {
-            fn update(&mut self) -> (
-                Option<Duration>,
-                Result<(), Box<dyn error::Error + Send + Sync + 'static>>,
-            ) {
-                (None, Ok(()))
+            fn update(&mut self) -> Update {
+                Update::default()
             }
 
             fn exists(&self) -> bool {