mirror of
https://github.com/status-im/status-react.git
synced 2025-02-19 22:28:40 +00:00
Fix broken realm sorting
This fixes bugs #2520 and #2484 The cause of the bugs is the fact that calling `.sorted` method on the realm resultset produces another resultset which is sorted when iterated through `Iterator<T>` interface, but does absolutely nothing to way how resultset object is serialised (printed out as JSON). So when we sorted, printed to json, parsed back through transit and expected the order to be retained, it was not, and it was failing quite randomly. To be precise, it failed in a case where we sorted the resultset according to some property and picked the top element from the result. As the top element picking was done AFTER the sorted realm resultset was converted into cljs datastructure, it was sometimes failing. This fix just ensures that we select the single element from js resultset (where sorting info is still retained) and only convert that single element to cljs (it's also much more efficient).
This commit is contained in:
parent
0730420017
commit
56eb3f7a43
@ -73,7 +73,7 @@
|
|||||||
(reset! account-realm (open-migrated-realm address account/schemas))
|
(reset! account-realm (open-migrated-realm address account/schemas))
|
||||||
(handler nil)))))
|
(handler nil)))))
|
||||||
|
|
||||||
; realm functions
|
;; realm functions
|
||||||
|
|
||||||
(defn and-query [queries]
|
(defn and-query [queries]
|
||||||
(str/join " and " queries))
|
(str/join " and " queries))
|
||||||
@ -128,17 +128,19 @@
|
|||||||
|
|
||||||
(def reader (transit/reader :json))
|
(def reader (transit/reader :json))
|
||||||
|
|
||||||
|
(defn- internal-convert [js-object]
|
||||||
|
(->> js-object
|
||||||
|
(.stringify js/JSON)
|
||||||
|
(transit/read reader)
|
||||||
|
walk/keywordize-keys))
|
||||||
|
|
||||||
(defn js-object->clj
|
(defn js-object->clj
|
||||||
"Converts any js type/object into a map recursively
|
"Converts any js type/object into a map recursively
|
||||||
Performs 5 times better than iterating over the object keys
|
Performs 5 times better than iterating over the object keys
|
||||||
and that would require special care for collections"
|
and that would require special care for collections"
|
||||||
[js-object]
|
[js-object]
|
||||||
(let [o (->> js-object
|
(let [o (internal-convert js-object)]
|
||||||
(.stringify js/JSON)
|
(if (map? o) (map->vec o) o)))
|
||||||
(transit/read reader))]
|
|
||||||
(walk/keywordize-keys (if (map? o)
|
|
||||||
(map->vec o)
|
|
||||||
o))))
|
|
||||||
|
|
||||||
(defn fix-map->vec
|
(defn fix-map->vec
|
||||||
"Takes a map m and a keyword k
|
"Takes a map m and a keyword k
|
||||||
@ -161,8 +163,8 @@
|
|||||||
(defn single [result]
|
(defn single [result]
|
||||||
(aget result 0))
|
(aget result 0))
|
||||||
|
|
||||||
(def single-clj
|
(defn single-clj [results]
|
||||||
(comp first js-object->clj))
|
(some-> results single internal-convert))
|
||||||
|
|
||||||
(defn- get-schema-by-name [opts]
|
(defn- get-schema-by-name [opts]
|
||||||
(->> opts
|
(->> opts
|
||||||
|
Loading…
x
Reference in New Issue
Block a user