From 5f8d5fd57e516d184c627f4b59cd807ba4a9a6f4 Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Thu, 28 Nov 2024 08:46:32 -0300 Subject: [PATCH] perf: Optimize messenger initialization (#21642) Integrates the optimizations coming from the status-go PR https://github.com/status-im/status-go/pull/6106. Now messenger filters are set-up concurrently and we can call the endpoint wakuext_chatsPreview twice: once for non-community chats and once for community chats. This way, the user should be able to see some data render before the slow part ends (community-related data). Fixes https://github.com/status-im/status-mobile/issues/21456 Areas that may be impacted - Login - Loading of data after login (contacts, chats, etc) --- src/legacy/status_im/chat/models/loading.cljs | 36 +++++++++---------- src/legacy/status_im/data_store/chats.cljs | 4 +-- src/legacy/status_im/utils/logging/core.cljs | 1 - src/status_im/constants.cljs | 3 ++ .../contexts/profile/login/events.cljs | 22 +++++++----- src/status_im/subs/root.cljs | 1 - status-go-version.json | 6 ++-- 7 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/legacy/status_im/chat/models/loading.cljs b/src/legacy/status_im/chat/models/loading.cljs index d0d33937b3..a0e10de5f7 100644 --- a/src/legacy/status_im/chat/models/loading.cljs +++ b/src/legacy/status_im/chat/models/loading.cljs @@ -18,25 +18,23 @@ clock-value "0x0000000000000000000000000000000000000000000000000000000000000000")) -(rf/defn update-chats-in-app-db - {:events [:chats-list/load-success]} - [{:keys [db]} ^js new-chats-js] - (let [{:keys [all-chats chats-home-list]} - (reduce (fn [acc ^js chat-js] - (let [{:keys [chat-id profile-public-key timeline? community-id active] :as chat} - (data-store.chats/<-rpc-js chat-js)] - (cond-> acc - (and (not profile-public-key) (not timeline?) (not community-id) active) - (update :chats-home-list conj chat-id) - :always - (assoc-in [:all-chats chat-id] chat)))) - {:all-chats {} - :chats-home-list #{}} - new-chats-js)] - {:db (assoc db - :chats all-chats - :chats-home-list chats-home-list - :chats/loading? false)})) +(rf/reg-event-fx :chats-list/load-success + (fn [{:keys [db]} [^js new-chats-js]] + (let [{:keys [all-chats chats-home-list]} + (reduce (fn [acc ^js chat-js] + (let [{:keys [chat-id profile-public-key timeline? community-id active] :as chat} + (data-store.chats/<-rpc-js chat-js)] + (cond-> acc + (and (not profile-public-key) (not timeline?) (not community-id) active) + (update :chats-home-list conj chat-id) + :always + (assoc-in [:all-chats chat-id] chat)))) + {:all-chats {} + :chats-home-list #{}} + new-chats-js)] + {:db (-> db + (update :chats merge all-chats) + (update :chats-home-list into chats-home-list))}))) (rf/defn load-chat-success {:events [:chats-list/load-chat-success]} diff --git a/src/legacy/status_im/data_store/chats.cljs b/src/legacy/status_im/data_store/chats.cljs index ab685cb8b1..392699d059 100644 --- a/src/legacy/status_im/data_store/chats.cljs +++ b/src/legacy/status_im/data_store/chats.cljs @@ -134,9 +134,9 @@ unmarshal-members)) (re-frame/reg-fx :fetch-chats-preview - (fn [{:keys [on-success]}] + (fn [{:keys [on-success chat-preview-type]}] (json-rpc/call {:method "wakuext_chatsPreview" - :params [] + :params [chat-preview-type] :js-response true :on-success #(on-success ^js %) :on-error #(log/error "failed to fetch chats" 0 -1 %)}))) diff --git a/src/legacy/status_im/utils/logging/core.cljs b/src/legacy/status_im/utils/logging/core.cljs index eae886a6a6..270ae5ef99 100644 --- a/src/legacy/status_im/utils/logging/core.cljs +++ b/src/legacy/status_im/utils/logging/core.cljs @@ -135,7 +135,6 @@ :chat/cooldowns :chat/last-outgoing-message-sent-at :chat/spam-messages-frequency - :chats/loading? :dimensions/window]))] {:logs/archive-logs [db-json (if (= transport :email) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index f298b0a249..e2ec395ba9 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -76,6 +76,9 @@ (def ^:const timeline-chat-type 5) (def ^:const community-chat-type 6) +(def ^:const chat-preview-type-community 0) +(def ^:const chat-preview-type-non-community 1) + (def ^:const contact-request-message-state-none 0) (def ^:const contact-request-message-state-pending 1) (def ^:const contact-request-message-state-accepted 2) diff --git a/src/status_im/contexts/profile/login/events.cljs b/src/status_im/contexts/profile/login/events.cljs index 9df55d2b00..faba267345 100644 --- a/src/status_im/contexts/profile/login/events.cljs +++ b/src/status_im/contexts/profile/login/events.cljs @@ -4,6 +4,7 @@ [native-module.core :as native-module] [status-im.common.keychain.events :as keychain] [status-im.config :as config] + [status-im.constants :as constants] status-im.contexts.profile.login.effects [status-im.contexts.profile.rpc :as profile.rpc] [taoensso.timbre :as log] @@ -41,10 +42,10 @@ log-level (or (:log-level settings) config/log-level) pairing-completed? (= (get-in db [:syncing :pairing-status]) :completed) new-db (-> db - (assoc :chats/loading? true - :profile/profile (merge profile-overview - settings - {:log-level log-level})) + (assoc :profile/profile + (merge profile-overview + settings + {:log-level log-level})) (assoc-in [:activity-center :loading?] true) (dissoc :centralized-metrics/onboarding-enabled?))] {:db (cond-> new-db @@ -131,10 +132,15 @@ (let [new-account? (get db :onboarding/new-account?)] {:db (assoc db :messenger/started? true) :fx [[:fetch-chats-preview - {:on-success (fn [result] - (rf/dispatch [:chats-list/load-success result]) - (rf/dispatch [:communities/get-user-requests-to-join]) - (rf/dispatch [:profile.login/get-chats-callback]))}] + {:chat-preview-type constants/chat-preview-type-non-community + :on-success (fn [result] + (rf/dispatch [:chats-list/load-success result]) + (rf/dispatch [:profile.login/get-chats-callback]))}] + [:fetch-chats-preview + {:chat-preview-type constants/chat-preview-type-community + :on-success (fn [result] + (rf/dispatch [:chats-list/load-success result]) + (rf/dispatch [:communities/get-user-requests-to-join]))}] (when (and (:syncing/fallback-flow? db) (:syncing/installation-id db)) [:dispatch [:pairing/finish-seed-phrase-fallback-syncing]]) (when-not new-account? diff --git a/src/status_im/subs/root.cljs b/src/status_im/subs/root.cljs index 4b27862673..3a2254f9f4 100644 --- a/src/status_im/subs/root.cljs +++ b/src/status_im/subs/root.cljs @@ -100,7 +100,6 @@ (reg-root-key-sub :chats/chats :chats) (reg-root-key-sub :chats/current-chat-id :current-chat-id) (reg-root-key-sub :public-group-topic :public-group-topic) -(reg-root-key-sub :chats/loading? :chats/loading?) (reg-root-key-sub :new-chat-name :new-chat-name) (reg-root-key-sub :chat/inputs :chat/inputs) (reg-root-key-sub :chat/memberships :chat/memberships) diff --git a/status-go-version.json b/status-go-version.json index ef3f1ec88d..86c82cedaf 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v4.0.0", - "commit-sha1": "032eb5b6ee71b675b7d1d63198e79e2c18063654", - "src-sha256": "06qffndymgl80c08w96rs02ycxigai7y06d7ljwrkfr4brc86r21" + "version": "v6.0.0", + "commit-sha1": "83ea49fc04cd521864a64fd2d94d4e5309a81645", + "src-sha256": "0f93s1yr8p24aw9ji5wsmq07vf4599nk4bhr55q0ifx0szhabilx" }