Skip to content
Browse files

Fix for "___ solved and counting"

Need to iterate over :solved keys to get the total, as well as over
:scores to get per-problem scores, because many problems were solved
before we started tracking scores. We still update :solved, so this
will get all problems.
  • Loading branch information...
1 parent 27bcccf commit e15ec09c92e4c710eba220796ed2754b71326a16 @amalloy amalloy committed
Showing with 11 additions and 11 deletions.
  1. +11 −11 src/foreclojure/mongo.clj
View
22 src/foreclojure/mongo.clj
@@ -43,17 +43,17 @@
(defn reconcile-solved-count
"Overwrites the times-solved field in the problems collection based on data from the users collection. Should only be called on server startup since it isn't a safe operation. Also updates the total-solved agent."
[]
- (let [+ (fnil + 0)
- [total scores]
- (->> (fetch :users :only [:scores])
- (mapcat :scores)
- (frequencies)
- (reduce (fn [[total scores] [[id score] times]]
- [(+ total times)
- (update-in scores
- [(number-from-mongo-key id) score]
- + times)])
- [0 {}]))]
+ (let [+ (fnil + 0)
+ users (fetch :users :only [:scores :solved])
+ scores (->> users
+ (mapcat :scores)
+ (frequencies)
+ (reduce (fn [scores [[id score] times]]
+ (update-in scores
+ [(number-from-mongo-key id) score]
+ + times))
+ {}))
+ total (count (mapcat :solved users))]
(send solved-stats (constantly (assoc scores :total total)))))
(defn prepare-mongo []

0 comments on commit e15ec09

Please sign in to comment.
Something went wrong with that request. Please try again.