summary refs log tree commit diff stats
path: root/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/data')
-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
4 files changed, 35 insertions, 100 deletions
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 {