Skip to content

Commit

Permalink
Limit the number of seq items sent to the client to 1k
Browse files Browse the repository at this point in the history
  • Loading branch information
djblue committed Oct 20, 2020
1 parent 7fb139b commit 7083beb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions dev/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

(def portal (p/open))
(p/tap)
(tap> (with-meta (range) {:hello :world}))
(tap> [{:hello :world :old-key 123} {:hello :youtube :new-key 123}])
(doseq [i (range 100)] (tap> [::index i]))
(p/clear)
Expand Down
5 changes: 4 additions & 1 deletion src/portal/runtime/transit.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

(defn- find-var [s] (get @rt/instance-cache [:var s]))

(defn- limit-seq [value]
(if (seq? value) (take 1000 value) value))

(defn edn->json-stream [value out]
(let [writer
(transit/writer
Expand All @@ -22,7 +25,7 @@
(transit/write-handler "portal.transit/var" var->symbol)
java.net.URL
(transit/write-handler "r" str)}
:transform transit/write-meta
:transform (comp limit-seq transit/write-meta)
:default-handler
(transit/write-handler
"portal.transit/object"
Expand Down
5 changes: 4 additions & 1 deletion src/portal/runtime/transit.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@

:else x))

(defn- limit-seq [value]
(if (seq? value) (take 1000 value) value))

(defn edn->json [edn]
(t/write
(t/writer
:json
{:transform write-meta
{:transform (comp limit-seq write-meta)
:handlers
{js/URL
(t/write-handler (constantly "r") str)
Expand Down

0 comments on commit 7083beb

Please sign in to comment.