Add setting to control how many epochs are retained

This commit is contained in:
Daniel Compton 2018-01-26 15:46:54 +13:00
parent 05c9f84225
commit db14e69f17
4 changed files with 28 additions and 11 deletions

View File

@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file. This change
## Unreleased
### Added
* Setting to control how many epochs are retained
* Setting to reset all epochs
### Changed
* Updated bundled re-frame version to 0.10.3, and bundled reagent version to 0.7.0. This shouldn't impact your project's dependencies as they are source bundled via [mranderson](https://github.com/benedekfazekas/mranderson).

View File

@ -11,7 +11,7 @@
json-ml-paths (localstorage/get "app-db-json-ml-expansions" #{})
external-window? (localstorage/get "external-window?" false)
using-trace? (localstorage/get "using-trace?" true)
num-epochs (localstorage/get "retained-epochs" 30)
num-epochs (localstorage/get "retained-epochs" 5)
categories (localstorage/get "categories" #{:event :sub/run :sub/create :sub/dispose})]
(when using-trace?
(rf/dispatch [:global/enable-tracing]))

View File

@ -14,8 +14,11 @@
[day8.re-frame.trace.metamorphic :as metam]
[re-frame.trace]))
(def default-number-of-epochs-to-retain 5)
(defonce traces (r/atom []))
(defonce total-traces (r/atom 0))
(defonce number-of-epochs-to-retain (atom default-number-of-epochs-to-retain))
(defn log-trace? [trace]
(let [render-operation? (or (= (:op-type trace) :render)
@ -43,8 +46,16 @@
(do (reset! total-traces 0)
(into [] new2))))
new))))
(rf/dispatch [:traces/update-traces @traces])
(rf/dispatch [:epochs/update-epochs (metam/parse-traces @traces)])))))
;; TODO: there is a bit of double handling here, that will be cleaned up
;; when the epoch parsing is refactored.
(let [epochs (metam/parse-traces @traces)
retained-epochs (take-last @number-of-epochs-to-retain (:matches epochs))
first-id-to-retain (:id (ffirst retained-epochs))
new-traces (into [] (drop-while #(< (:id %) first-id-to-retain)) @traces)]
(reset! traces new-traces)
(reset! total-traces (count new-traces))
(rf/dispatch [:traces/update-traces new-traces])
(rf/dispatch [:epochs/update-epochs {:matches retained-epochs}]))))))
(defn dissoc-in
"Dissociates an entry from a nested associative structure returning a new
@ -133,10 +144,13 @@
;; TODO: this is not perfect, there is an issue in re-com
;; where it won't update its model if it never receives another
;; changes after it's on-change is fired.
;; TODO: you could reset the stored epochs on change here
;; once the way they are processed is refactored.
(let [num (js/parseInt num-str)
num (if (and (not (js/isNaN num)) (pos-int? num))
num
30)]
default-number-of-epochs-to-retain)]
(reset! number-of-epochs-to-retain num)
(localstorage/save! "retained-epochs" num)
(assoc-in db [:settings :number-of-epochs] num))))
@ -478,12 +492,11 @@
(rf/reg-event-db
:epochs/reset
[(rf/path [:epochs])]
(fn [epochs]
(fn [db]
(re-frame.trace/reset-tracing!)
(reset! traces [])
(reset! total-traces 0)
nil))
(dissoc db :epochs :traces)))
(rf/reg-event-db
:traces/update-traces

View File

@ -97,8 +97,7 @@
num-traces @(rf/subscribe [:traces/number-of-traces])
epochs-to-retain (rf/subscribe [:settings/number-of-retained-epochs])]
;; TODO: retain last
#_[settings-box
[settings-box
[[rc/h-box
:align :center
:gap horizontal-gap
@ -118,7 +117,7 @@
:label [rc/v-box
:align :center
:children ["clear all epochs"]]
:on-click #(println "Clicked CLEAR")]]]]
:on-click #(rf/dispatch [:epochs/reset])]]]]
[[:p num-epochs " epochs currently retained, involving " num-traces " traces."]]
settings-box-81])
@ -194,7 +193,7 @@
[[:p "Most of the time, low level trace is noisy and you want it filtered out."]]
settings-box-131])
#_[rc/line]
[rc/line]
[settings-box
[[rc/button
:class "bm-muted-button app-db-panel-button"