Skip to content

Commit

Permalink
Check only 10000 last modified documents per collection
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenttila committed Jan 18, 2020
1 parent 0a13dba commit d000158
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject lupapiste/mongocheck "0.1.4-alpha3"
(defproject lupapiste/mongocheck "0.1.4-alpha4"
:description "Library for running checks on MongoDB data"
:url "http://www.solita.fi"
:license {:name "Eclipse Public License"
Expand Down
32 changes: 19 additions & 13 deletions src/lupapiste/mongocheck/core.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns lupapiste.mongocheck.core
"Library for running checks on MongoDB data."
(:require [clojure.set :refer [union]]
[monger.collection :as mc]))
[monger.query :as mq]))

(defonce ^:private checks (atom {}))

Expand All @@ -18,7 +18,7 @@

(defn- update-columns [columns interesting-properties]
(let [new-columns (->columns interesting-properties)]
(if (or (empty-set? columns) ; columns is empty set = select all properties
(if (or (empty-set? columns) ; columns is empty set = select all properties
(empty-set? new-columns)) ; no new properties = select all properties
#{}
(union columns new-columns))))
Expand All @@ -39,24 +39,30 @@
(->> checks
(map (fn [f]
(let [start (System/currentTimeMillis)
res (try (f mongo-document)
(catch Throwable t
(.getMessage t)))]
res (try (f mongo-document)
(catch Throwable t
(.getMessage t)))]
[res (str f) (- (System/currentTimeMillis) start)])))
doall))

(defn- execute-collection-checks [db collection {:keys [columns checks]}]
(let [documents (mc/find-maps db collection {} (zipmap columns (repeat 1)))
results (->> documents
(pmap (fn [mongo-document]
(let [[errors fn-name time] (errors-for-document mongo-document checks)]
[time fn-name (when (seq errors)
[(:_id mongo-document) errors])]))))]
(let [documents (mq/with-collection db collection
(mq/find {})
(mq/fields columns)
(mq/sort (array-map :modified -1))
(mq/limit 10000))
results (->> documents
(pmap (fn [mongo-document]
(let [[errors fn-name time] (errors-for-document mongo-document checks)]
[time fn-name (when (seq errors)
[(:_id mongo-document) errors])]))))]
(try
(->> results
(filter #(-> % first number?))
(filter (fn [[ms _ _]]
(and (number? ms)
(> ms 1))))
(sort-by first >)
(take 1000)
(take 100)
(map println)
doall)
(catch Throwable t
Expand Down

0 comments on commit d000158

Please sign in to comment.