[slow sign in] faster :get-referenced-messages

This commit is contained in:
Roman Volosovskyi 2018-11-21 09:44:31 +02:00
parent 79c149af7d
commit 1dcc7727f1
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
3 changed files with 11 additions and 13 deletions

View File

@ -73,7 +73,6 @@
:referenced-messages (into {} :referenced-messages (into {}
(map (juxt :message-id identity) (map (juxt :message-id identity)
(get-referenced-messages (get-referenced-messages
chat-id
(get-referenced-ids chat-messages)))))))) (get-referenced-ids chat-messages))))))))
{} {}
all-stored-chats)] all-stored-chats)]
@ -116,8 +115,7 @@
new-messages (get-stored-messages current-chat-id loaded-count) new-messages (get-stored-messages current-chat-id loaded-count)
indexed-messages (index-messages new-messages) indexed-messages (index-messages new-messages)
referenced-messages (index-messages referenced-messages (index-messages
(get-referenced-messages current-chat-id (get-referenced-messages (get-referenced-ids indexed-messages)))
(get-referenced-ids indexed-messages)))
new-message-ids (keys indexed-messages) new-message-ids (keys indexed-messages)
new-statuses (get-stored-user-statuses current-chat-id new-message-ids)] new-statuses (get-stored-user-statuses current-chat-id new-message-ids)]
(fx/merge cofx (fx/merge cofx

View File

@ -21,15 +21,15 @@
(core/all-clj :message))] (core/all-clj :message))]
(map transform-message messages)))) (map transform-message messages))))
(defn- get-by-chat-and-messages-ids (defn- get-by-messages-ids
[chat-id message-ids] [message-ids]
(when (seq message-ids) (when (seq message-ids)
(let [messages (-> @core/account-realm (keep (fn [message-id]
(.objects "message") (when-let [js-message (.objectForPrimaryKey @core/account-realm "message" message-id)]
(.filtered (str "chat-id=\"" chat-id "\"" (-> js-message
(str " and (" (core/in-query "message-id" message-ids) ")"))) (core/realm-obj->clj :message)
(core/all-clj :message))] transform-message)))
(map transform-message messages)))) message-ids)))
(def default-values (def default-values
{:to nil}) {:to nil})
@ -101,7 +101,7 @@
(re-frame/reg-cofx (re-frame/reg-cofx
:data-store/get-referenced-messages :data-store/get-referenced-messages
(fn [cofx _] (fn [cofx _]
(assoc cofx :get-referenced-messages get-by-chat-and-messages-ids))) (assoc cofx :get-referenced-messages get-by-messages-ids)))
(defn- prepare-content [content] (defn- prepare-content [content]
(if (string? content) (if (string? content)

View File

@ -275,7 +275,7 @@
#(let [realm-obj (object/get realm-object-list %)] #(let [realm-obj (object/get realm-object-list %)]
[(object/get realm-obj primary-key) (realm-obj->clj realm-obj entity-name)])))) [(object/get realm-obj primary-key) (realm-obj->clj realm-obj entity-name)]))))
(defn- realm-obj->clj [realm-obj entity-name] (defn realm-obj->clj [realm-obj entity-name]
(when realm-obj (when realm-obj
(let [{:keys [primaryKey properties]} (get entity->schemas entity-name)] (let [{:keys [primaryKey properties]} (get entity->schemas entity-name)]
(into {} (into {}