From bc9e65774c7339de72eab2e41cf10378fd32c2a8 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 28 Sep 2017 20:07:37 +0200 Subject: [PATCH] remove duplicate calls to jail --- src/status_im/native_module/impl/module.cljs | 49 +++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/status_im/native_module/impl/module.cljs b/src/status_im/native_module/impl/module.cljs index ad1aa2f503..d71b223db3 100644 --- a/src/status_im/native_module/impl/module.cljs +++ b/src/status_im/native_module/impl/module.cljs @@ -55,7 +55,7 @@ (call-module (fn [] (let [init-js (str js-res/status-js "I18n.locale = '" rn-dependencies/i18n.locale "';")] - (.initJail status init-js #(log/debug "jail initialized"))))))) + (.initJail status init-js #(log/debug "jail initialized"))))))) (defonce listener-initialized (atom false)) @@ -147,7 +147,7 @@ (when status (call-module #(.parseJail status chat-id file callback)))) -(defn call-jail [{:keys [jail-id path params callback]}] +(defn execute-call [{:keys [jail-id path params callback]}] (when status (call-module #(do @@ -167,6 +167,51 @@ (callback r')))] (.callJail status jail-id (types/clj->json path) (types/clj->json params') cb)))))) +;; TODO(rasom): temporal solution, should be fixed on status-go side +(def check-raw-calls-interval 400) +(def interval-between-calls 100) +;; contains all calls to jail before with duplicates +(def raw-jail-calls (atom '())) +;; contains only calls that passed duplication check +(def jail-calls (atom '())) + +(defn remove-duplicate-calls + "Removes duplicates by [jail path] keys, remains the last one." + [[all-keys calls] {:keys [jail-id path] :as call}] + (if (contains? all-keys [jail-id path]) + [all-keys calls] + [(conj all-keys [jail-id path]) + (conj calls call)])) + +(defn check-raw-calls-loop! + "Only the last call with [jail path] key is added to jail-calls list + from raw-jail-calls" + [] + (go-loop [_ nil] + (let [[_ new-calls] (reduce remove-duplicate-calls [#{} '()] @raw-jail-calls)] + (reset! raw-jail-calls '()) + (swap! jail-calls (fn [old-calls] + (concat new-calls old-calls)))) + (recur (