attempt to fix performance issues

Former-commit-id: 3a93e0890b
This commit is contained in:
Roman Volosovskyi 2016-06-30 17:23:38 +03:00
parent 2280fd7124
commit b746bcef4f
13 changed files with 32 additions and 20 deletions

View File

@ -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)

View File

@ -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]

View File

@ -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]

View File

@ -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)

View File

@ -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]

View File

@ -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]

View File

@ -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]

View File

@ -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))))))

View File

@ -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

View File

@ -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]))

View File

@ -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 _]

View File

@ -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]]

View File

@ -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]))