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

View File

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

View File

@ -275,7 +275,7 @@
#(let [realm-obj (object/get realm-object-list %)]
[(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
(let [{:keys [primaryKey properties]} (get entity->schemas entity-name)]
(into {}