summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-04-30 21:07:56 +0200
committerGitHub <noreply@github.com>2018-04-30 21:07:56 +0200
commit424a060cc84afee3875357e18e4746f789de4872 (patch)
tree108fcf9d0294964fcc1ead87c4e1aae65fe62a4e /bin
parent900d9f0984fc64e6c9d59d853f27c294cba33a1c (diff)
parent004faaa905b58ebcf0a41fd0f2f075d72a19359c (diff)
Merge pull request #1475 from matthiasbeyer/imag-diagnostics/flush-cache
imag-diagnostics: flush cache
Diffstat (limited to 'bin')
-rw-r--r--bin/core/imag-diagnostics/Cargo.toml1
-rw-r--r--bin/core/imag-diagnostics/src/main.rs24
2 files changed, 23 insertions, 2 deletions
diff --git a/bin/core/imag-diagnostics/Cargo.toml b/bin/core/imag-diagnostics/Cargo.toml
index c591e0c4..330c6a33 100644
--- a/bin/core/imag-diagnostics/Cargo.toml
+++ b/bin/core/imag-diagnostics/Cargo.toml
@@ -16,6 +16,7 @@ homepage = "http://imag-pim.org"
build = "../../../build.rs"
[dependencies]
+log = "0.4"
toml = "0.4"
toml-query = "0.6"
diff --git a/bin/core/imag-diagnostics/src/main.rs b/bin/core/imag-diagnostics/src/main.rs
index 63f3df99..a0cf9cf8 100644
--- a/bin/core/imag-diagnostics/src/main.rs
+++ b/bin/core/imag-diagnostics/src/main.rs
@@ -35,6 +35,7 @@
extern crate clap;
extern crate toml;
extern crate toml_query;
+#[macro_use] extern crate log;
#[macro_use] extern crate libimagrt;
extern crate libimagerror;
@@ -59,6 +60,7 @@ use std::collections::BTreeMap;
mod ui;
+#[derive(Debug)]
struct Diagnostic {
pub id: StoreId,
pub entry_store_version: String,
@@ -71,7 +73,7 @@ struct Diagnostic {
impl Diagnostic {
- fn for_entry<'a>(entry: FileLockEntry<'a>) -> Result<Diagnostic, ::libimagstore::error::StoreError> {
+ fn for_entry<'a>(entry: &FileLockEntry<'a>) -> Result<Diagnostic, ::libimagstore::error::StoreError> {
Ok(Diagnostic {
id: entry.get_location().clone(),
entry_store_version: entry
@@ -102,6 +104,7 @@ fn main() {
"Print diagnostics about imag and the imag store",
ui::build_ui);
+ let mut entries_counter = 0;
let diags = rt.store()
.entries()
.map_err_trace_exit_unwrap(1)
@@ -111,7 +114,24 @@ fn main() {
.ok_or(Error::from("Unable to get entry".to_owned()))
.map_err_trace_exit_unwrap(1)
})
- .map(Diagnostic::for_entry)
+ .map(|e| {
+ let diag = Diagnostic::for_entry(&e);
+ debug!("Diagnostic for '{:?}' = {:?}", e.get_location(), diag);
+ drop(e);
+
+ entries_counter += 1;
+
+ // because we're effectively reading _all_ store entries here.
+ //
+ // The store has an API for it, but the cache size calculation is O(n) and we can do
+ // better by simply flushing the cache each 100 entries
+ if entries_counter > 100 {
+ let _ = rt.store().flush_cache().map_err_trace_exit_unwrap(1);
+ entries_counter = 0;
+ }
+
+ diag
+ })
.collect::<Result<Vec<_>, _>>()
.map_err_trace_exit_unwrap(1);