From d4c5784b4aa6c51bbd562d33b7142ac64e32a4cf Mon Sep 17 00:00:00 2001 From: gered Date: Wed, 11 May 2016 09:27:22 -0400 Subject: [PATCH] switch to cheshire for json encoding cheshire is significantly faster then data.json. i'm assuming the only reason data.json was being used was due to the age of this project --- clj-browserchannel/project.clj | 2 +- .../src/net/thegeez/browserchannel/server.clj | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clj-browserchannel/project.clj b/clj-browserchannel/project.clj index ad99364..7af5353 100644 --- a/clj-browserchannel/project.clj +++ b/clj-browserchannel/project.clj @@ -1,7 +1,7 @@ (defproject gered/clj-browserchannel "0.3" :description "BrowserChannel server implementation in Clojure, with a ClojureScript wrapper for the BrowserChannel API included in Google Closure." :dependencies [[ring/ring-core "1.4.0"] - [org.clojure/data.json "0.2.6"] + [cheshire "5.6.1"] [prismatic/dommy "1.1.0"]] :profiles {:provided {:dependencies diff --git a/clj-browserchannel/src/net/thegeez/browserchannel/server.clj b/clj-browserchannel/src/net/thegeez/browserchannel/server.clj index ea96804..9273f4b 100644 --- a/clj-browserchannel/src/net/thegeez/browserchannel/server.clj +++ b/clj-browserchannel/src/net/thegeez/browserchannel/server.clj @@ -4,7 +4,7 @@ [java.util.concurrent ScheduledExecutorService Executors TimeUnit Callable ScheduledFuture]) (:require [clojure.edn :as edn] - [clojure.data.json :as json] + [cheshire.core :as json] [ring.middleware.params :as params] [net.thegeez.browserchannel.async-adapter :as async-adapter])) @@ -231,7 +231,7 @@ (async-adapter/head respond 200 (merge headers ie-headers)) (async-adapter/write-chunk respond "\n") (when (seq domain) - (async-adapter/write-chunk respond (str "\n")))) + (async-adapter/write-chunk respond (str "\n")))) (write [this data] (async-adapter/write-chunk respond (str "\n")) @@ -597,7 +597,7 @@ (defn- send-map [session-id m] (when-let [session-agent (get @sessions session-id)] - (let [string (json/write-str m)] + (let [string (json/generate-string m)] (send-off session-agent #(-> % (queue-string string) flush-buffer)) @@ -684,7 +684,7 @@ (rand-nth prefixes))] {:status 200 :headers (assoc (:headers options) "X-Accept" "application/json; application/x-www-form-urlencoded") - :body (json/write-str [host-prefix, nil])}) + :body (json/generate-string [host-prefix, nil])}) ;; else phase 2 for get /test ;; client checks if connection is buffered @@ -720,7 +720,7 @@ host-prefix nil] {:status 200 :headers (assoc (:headers options) "Content-Type" "application/javascript") - :body (size-json-str (json/write-str [[0, ["c", session-id, host-prefix, 8]]]))}) + :body (size-json-str (json/generate-string [[0, ["c", session-id, host-prefix, 8]]]))}) ;; For existing sessions: ;; Forward sent data by client to listeners ;; reply with @@ -734,7 +734,7 @@ (let [status (session-status @session-agent)] {:status 200 :headers (:headers options) - :body (size-json-str (json/write-str status))}))))) + :body (size-json-str (json/generate-string status))}))))) ;; GET req server->client is a backwardchannel opened by client (defn- handle-backward-channel