From b746bcef4f1d543ca7dd13ec204fbcdb4fe61a0b Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 17:23:38 +0300 Subject: [PATCH] attempt to fix performance issues Former-commit-id: 3a93e0890bfea4b167b934c26f2c5096ea73421a --- src/status_im/chat/handlers.cljs | 18 ++++++++++++------ src/status_im/commands/handlers/loading.cljs | 3 +-- src/status_im/commands/utils.cljs | 2 +- src/status_im/constants.cljs | 2 +- src/status_im/contacts/handlers.cljs | 3 ++- src/status_im/discovery/handlers.cljs | 3 ++- src/status_im/group_settings/handlers.cljs | 4 ++-- src/status_im/models/messages.cljs | 2 +- src/status_im/navigation/handlers.cljs | 3 ++- src/status_im/new_group/handlers.cljs | 3 ++- src/status_im/participants/handlers.cljs | 3 ++- src/status_im/protocol/handlers.cljs | 3 ++- src/status_im/qr_scanner/handlers.cljs | 3 ++- 13 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 248520ca44..05ab26564f 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -8,7 +8,8 @@ [status-im.models.messages :as messages] [status-im.constants :refer [text-content-type content-type-command - content-type-command-request]] + content-type-command-request + default-number-of-messages]] [status-im.utils.random :as random] [status-im.chat.sign-up :as sign-up-service] [status-im.models.chats :as chats] @@ -28,12 +29,17 @@ (assoc db :show-actions show-actions))) (register-handler :load-more-messages - debug (fn [{:keys [current-chat-id] :as db} _] - (let [messages-path [:chats current-chat-id :messages] - messages (get-in db messages-path) - new-messages (messages/get-messages current-chat-id (count messages))] - (update-in db messages-path concat new-messages)))) + (let [all-loaded? (get-in db [:chats current-chat-id :all-loaded?])] + (if all-loaded? + db + (let [messages-path [:chats current-chat-id :messages] + messages (get-in db messages-path) + new-messages (messages/get-messages current-chat-id (count messages)) + all-loaded? (> default-number-of-messages (count new-messages))] + (-> db + (update-in messages-path concat new-messages) + (assoc-in [:chats current-chat-id :all-loaded?] all-loaded?))))))) (defn safe-trim [s] (when (string? s) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index b7b26589fe..ccecdc86e5 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -1,7 +1,6 @@ (ns status-im.commands.handlers.loading (:require-macros [status-im.utils.slurp :refer [slurp]]) - (:require [re-frame.core :refer [register-handler after dispatch subscribe - trim-v debug]] + (:require [re-frame.core :refer [after dispatch subscribe trim-v debug]] [status-im.utils.handlers :as u] [status-im.utils.utils :refer [http-get toast]] [clojure.string :as s] diff --git a/src/status_im/commands/utils.cljs b/src/status_im/commands/utils.cljs index ca03a910cf..af728dabad 100644 --- a/src/status_im/commands/utils.cljs +++ b/src/status_im/commands/utils.cljs @@ -3,7 +3,7 @@ [clojure.walk :as w] [status-im.components.react :refer [text scroll-view view image touchable-highlight]] - [re-frame.core :refer [register-handler dispatch trim-v debug]] + [re-frame.core :refer [dispatch trim-v debug]] [status-im.utils.handlers :refer [register-handler]])) (defn json->clj [json] diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index d01788d834..41460b6cc9 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -16,4 +16,4 @@ (def response-input-hiding-duration 100) (def response-suggesstion-resize-duration 100) -(def default-number-of-messages 20) +(def default-number-of-messages 5) diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index 2e0cdc73a6..f61bed64d5 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -1,5 +1,6 @@ (ns status-im.contacts.handlers - (:require [re-frame.core :refer [register-handler after dispatch]] + (:require [re-frame.core :refer [after dispatch]] + [status-im.utils.handlers :refer [register-handler]] [status-im.models.contacts :as contacts] [status-im.utils.crypt :refer [encrypt]] [clojure.string :as s] diff --git a/src/status_im/discovery/handlers.cljs b/src/status_im/discovery/handlers.cljs index 2b227acefa..2f062260bc 100644 --- a/src/status_im/discovery/handlers.cljs +++ b/src/status_im/discovery/handlers.cljs @@ -1,5 +1,6 @@ (ns status-im.discovery.handlers - (:require [re-frame.core :refer [register-handler after dispatch enrich]] + (:require [re-frame.core :refer [after dispatch enrich]] + [status-im.utils.handlers :refer [register-handler]] [status-im.protocol.api :as api] [status-im.navigation.handlers :as nav] [status-im.discovery.model :as discoveries] diff --git a/src/status_im/group_settings/handlers.cljs b/src/status_im/group_settings/handlers.cljs index 82eab18d7b..6f5e94d558 100644 --- a/src/status_im/group_settings/handlers.cljs +++ b/src/status_im/group_settings/handlers.cljs @@ -1,6 +1,6 @@ (ns status-im.group-settings.handlers - (:require [re-frame.core :refer [register-handler debug dispatch after - enrich]] + (:require [re-frame.core :refer [debug dispatch after enrich]] + [status-im.utils.handlers :refer [register-handler]] [status-im.persistence.realm :as r] [status-im.chat.handlers :refer [delete-messages!]] [status-im.protocol.api :as api] diff --git a/src/status_im/models/messages.cljs b/src/status_im/models/messages.cljs index c010719ab1..38d7342ae3 100644 --- a/src/status_im/models/messages.cljs +++ b/src/status_im/models/messages.cljs @@ -56,7 +56,7 @@ (r/collection->map)) (into '()) reverse - (map (fn [{:keys [content-type] :as message}] + (keep (fn [{:keys [content-type] :as message}] (if (command-type? content-type) (update message :content str-to-map) message)))))) diff --git a/src/status_im/navigation/handlers.cljs b/src/status_im/navigation/handlers.cljs index cf73ae6434..db33411902 100644 --- a/src/status_im/navigation/handlers.cljs +++ b/src/status_im/navigation/handlers.cljs @@ -1,5 +1,6 @@ (ns status-im.navigation.handlers - (:require [re-frame.core :refer [register-handler dispatch debug enrich after]])) + (:require [re-frame.core :refer [dispatch debug enrich after]] + [status-im.utils.handlers :refer [register-handler]])) (defn push-view [db view-id] (-> db diff --git a/src/status_im/new_group/handlers.cljs b/src/status_im/new_group/handlers.cljs index 0c34111405..3cba0c3db0 100644 --- a/src/status_im/new_group/handlers.cljs +++ b/src/status_im/new_group/handlers.cljs @@ -1,6 +1,7 @@ (ns status-im.new-group.handlers (:require [status-im.protocol.api :as api] - [re-frame.core :refer [register-handler after dispatch debug enrich]] + [re-frame.core :refer [after dispatch debug enrich]] + [status-im.utils.handlers :refer [register-handler]] [status-im.components.styles :refer [default-chat-color]] [status-im.models.chats :as chats] [clojure.string :as s])) diff --git a/src/status_im/participants/handlers.cljs b/src/status_im/participants/handlers.cljs index fe0e5581c0..a6fb532355 100644 --- a/src/status_im/participants/handlers.cljs +++ b/src/status_im/participants/handlers.cljs @@ -1,6 +1,7 @@ (ns status-im.participants.handlers (:require [status-im.navigation.handlers :as nav] - [re-frame.core :refer [register-handler debug]])) + [re-frame.core :refer [debug]] + [status-im.utils.handlers :refer [register-handler]])) (defmethod nav/preload-data! :add-participants [db _] diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index a9b94e5541..e6e8c8699c 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -4,7 +4,8 @@ (:require [status-im.utils.handlers :as u] [status-im.utils.logging :as log] [status-im.protocol.api :as api] - [re-frame.core :refer [register-handler dispatch debug]] + [re-frame.core :refer [dispatch debug]] + [status-im.utils.handlers :refer [register-handler]] [status-im.models.contacts :as contacts] [status-im.protocol.api :refer [init-protocol]] [status-im.protocol.protocol-handler :refer [make-handler]] diff --git a/src/status_im/qr_scanner/handlers.cljs b/src/status_im/qr_scanner/handlers.cljs index be05d7fb65..8827ea847a 100644 --- a/src/status_im/qr_scanner/handlers.cljs +++ b/src/status_im/qr_scanner/handlers.cljs @@ -1,5 +1,6 @@ (ns status-im.qr-scanner.handlers - (:require [re-frame.core :refer [register-handler after dispatch debug enrich]] + (:require [re-frame.core :refer [after dispatch debug enrich]] + [status-im.utils.handlers :refer [register-handler]] [status-im.navigation.handlers :as nav] [status-im.utils.handlers :as u]))