From 6cce43f137e38bc07b9f21532a06a72b88b60db6 Mon Sep 17 00:00:00 2001 From: Sebastian Crane Date: Mon, 28 Mar 2022 21:52:52 +0100 Subject: [PATCH] Move processing out of clojure.data.json/read call This commit removes from the call to clojure.data.json/read the conversion of the serialised list of players into a Clojure set, and adds an independent function to do this task instead. Since the structure of the serialised data is known in advance, the recursive characteristics of clojure.data.json are not needed. Resolves issue https://git.libregaming.org/LibreGaming/matchbot/issues/4 Signed-off-by: Sebastian Crane --- src/system.clj | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/system.clj b/src/system.clj index f882c20..2ba7a37 100644 --- a/src/system.clj +++ b/src/system.clj @@ -6,21 +6,21 @@ [clojure.data.json :as json] [clj-yaml.core :as yaml])) -(defn json-data-reader [key value] - (if (= key :games) - (into (empty value) - (map #(hash-map (first %) - (set (second %))) - value)) - value)) +(defn setify-vals [x] + (reduce #(assoc %1 + (first %2) + (set (second %2))) + {} x)) + +(defn process-json [x] + (update x :games setify-vals)) (defn load-state [f] - (try - (with-open [datafile (clojure.java.io/reader f)] - (json/read datafile - :value-fn json-data-reader - :key-fn keyword)) - (catch Exception e nil))) + (process-json + (try + (with-open [datafile (clojure.java.io/reader f)] + (json/read datafile :key-fn keyword)) + (catch Exception e nil)))) (defn save-state [f data] (try