[perf] use objectForPrimaryKey instead of getByField

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2019-06-02 04:22:56 +02:00
parent 04ccd0e7d8
commit a1d6ead6d3
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
8 changed files with 27 additions and 23 deletions

View File

@ -20,5 +20,7 @@
"Returns tx function for removing browser"
[browser-id]
(fn [realm]
(let [browser (core/single (core/get-by-field realm :browser :browser-id browser-id))]
(let [browser (.objectForPrimaryKey realm
"browser"
browser-id)]
(core/delete realm browser))))

View File

@ -88,7 +88,7 @@
(core/delete realm (core/get-by-field realm :chat :chat chat-id))))
(defn- get-chat-by-id [chat-id realm]
(core/single (core/get-by-field realm :chat :chat-id chat-id)))
(.objectForPrimaryKey realm "chat" chat-id))
(defn clear-history-tx
"Returns tx function for clearing the history of chat"

View File

@ -2,9 +2,10 @@
(:require [status-im.data-store.realm.core :as core]))
(defn get-contact-recovery-by-id [public-key]
(-> @core/account-realm
(core/get-by-field :contact-recovery :id public-key)
(core/single-clj :contact-recovery)))
(core/realm-obj->clj (.objectForPrimaryKey @core/account-realm
"contact-recovery"
public-key)
:contact-recovery))
(defn save-contact-recovery-tx
"Returns tx function for saving a contact-recovery"

View File

@ -44,7 +44,7 @@
((save-contact-tx contact) realm))))
(defn- get-contact-by-id [public-key realm]
(core/single (core/get-by-field realm :contact :public-key public-key)))
(.objectForPrimaryKey realm "contact" public-key))
(defn- get-messages-by-messages-ids
[message-ids]

View File

@ -19,4 +19,4 @@
"Returns tx function for removing dapp permissions"
[dapp]
(fn [realm]
(core/delete realm (core/single (core/get-by-field realm :dapp-permissions :dapp dapp)))))
(core/delete realm (.objectForPrimaryKey realm "dapp" dapp))))

View File

@ -61,8 +61,9 @@
"Returns tx function for deleting mailserver topic"
[topic]
(fn [realm]
(let [mailserver-topic (core/single
(core/get-by-field realm :mailserver-topic :topic topic))]
(let [mailserver-topic (.objectForPrimaryKey realm
"mailserver-topic"
topic)]
(core/delete realm mailserver-topic))))
(defn save-chat-requests-range

View File

@ -1,14 +1,18 @@
(ns status-im.data-store.messages
(:require [re-frame.core :as re-frame]
[clojure.set :as clojure.set]
(:require [clojure.set :as clojure.set]
[clojure.string :as string]
[re-frame.core :as re-frame]
[status-im.constants :as constants]
[status-im.data-store.realm.core :as core]
[status-im.utils.core :as utils]
[status-im.js-dependencies :as dependencies]
[taoensso.timbre :as log]))
[status-im.utils.core :as utils]))
(defn- transform-message [{:keys [content] :as message}]
(defn get-message-by-id
[message-id realm]
(.objectForPrimaryKey realm "message" message-id))
(defn- transform-message
[{:keys [content outgoing-status] :as message}]
(when-let [parsed-content (utils/safe-read-message-content content)]
(-> message
(update :message-type keyword)
@ -60,7 +64,7 @@
(keep (fn [{:keys [response-to response-to-v2]}]
(when-let [js-message
(if response-to-v2
(.objectForPrimaryKey @core/account-realm "message" response-to-v2)
(get-message-by-id response-to-v2 @core/account-realm)
(core/single (core/get-by-field
@core/account-realm
:message :old-message-id response-to)))]
@ -124,18 +128,15 @@
"Returns tx function for deleting message"
[message-id]
(fn [realm]
(when-let [message (core/get-by-field realm :message :message-id message-id)]
(core/delete realm message)
(core/delete realm (core/get-by-field realm :user-status :message-id message-id)))))
(core/delete realm (get-message-by-id message-id realm))))
(defn delete-chat-messages-tx
"Returns tx function for deleting messages with user statuses for given chat-id"
[chat-id]
(fn [realm]
(core/delete realm (core/get-by-field realm :message :chat-id chat-id))
(core/delete realm (core/get-by-field realm :user-status :chat-id chat-id))))
(core/delete realm (core/get-by-field realm :message :chat-id chat-id))))
(defn message-exists? [message-id]
(if @core/account-realm
(not (nil? (.objectForPrimaryKey @core/account-realm "message" message-id)))
(not (nil? (get-message-by-id message-id @core/account-realm)))
false))

View File

@ -41,6 +41,5 @@
"Returns tx function for deleting transport"
[chat-id]
(fn [realm]
(let [transport (core/single
(core/get-by-field realm :transport :chat-id chat-id))]
(let [transport (.objectForPrimaryKey realm "transport" chat-id)]
(core/delete realm transport))))