[perf] use objectForPrimaryKey instead of getByField
Signed-off-by: yenda <eric@status.im>
This commit is contained in:
parent
04ccd0e7d8
commit
a1d6ead6d3
|
@ -20,5 +20,7 @@
|
||||||
"Returns tx function for removing browser"
|
"Returns tx function for removing browser"
|
||||||
[browser-id]
|
[browser-id]
|
||||||
(fn [realm]
|
(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))))
|
(core/delete realm browser))))
|
||||||
|
|
|
@ -88,7 +88,7 @@
|
||||||
(core/delete realm (core/get-by-field realm :chat :chat chat-id))))
|
(core/delete realm (core/get-by-field realm :chat :chat chat-id))))
|
||||||
|
|
||||||
(defn- get-chat-by-id [chat-id realm]
|
(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
|
(defn clear-history-tx
|
||||||
"Returns tx function for clearing the history of chat"
|
"Returns tx function for clearing the history of chat"
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
(:require [status-im.data-store.realm.core :as core]))
|
(:require [status-im.data-store.realm.core :as core]))
|
||||||
|
|
||||||
(defn get-contact-recovery-by-id [public-key]
|
(defn get-contact-recovery-by-id [public-key]
|
||||||
(-> @core/account-realm
|
(core/realm-obj->clj (.objectForPrimaryKey @core/account-realm
|
||||||
(core/get-by-field :contact-recovery :id public-key)
|
"contact-recovery"
|
||||||
(core/single-clj :contact-recovery)))
|
public-key)
|
||||||
|
:contact-recovery))
|
||||||
|
|
||||||
(defn save-contact-recovery-tx
|
(defn save-contact-recovery-tx
|
||||||
"Returns tx function for saving a contact-recovery"
|
"Returns tx function for saving a contact-recovery"
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
((save-contact-tx contact) realm))))
|
((save-contact-tx contact) realm))))
|
||||||
|
|
||||||
(defn- get-contact-by-id [public-key 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
|
(defn- get-messages-by-messages-ids
|
||||||
[message-ids]
|
[message-ids]
|
||||||
|
|
|
@ -19,4 +19,4 @@
|
||||||
"Returns tx function for removing dapp permissions"
|
"Returns tx function for removing dapp permissions"
|
||||||
[dapp]
|
[dapp]
|
||||||
(fn [realm]
|
(fn [realm]
|
||||||
(core/delete realm (core/single (core/get-by-field realm :dapp-permissions :dapp dapp)))))
|
(core/delete realm (.objectForPrimaryKey realm "dapp" dapp))))
|
||||||
|
|
|
@ -61,8 +61,9 @@
|
||||||
"Returns tx function for deleting mailserver topic"
|
"Returns tx function for deleting mailserver topic"
|
||||||
[topic]
|
[topic]
|
||||||
(fn [realm]
|
(fn [realm]
|
||||||
(let [mailserver-topic (core/single
|
(let [mailserver-topic (.objectForPrimaryKey realm
|
||||||
(core/get-by-field realm :mailserver-topic :topic topic))]
|
"mailserver-topic"
|
||||||
|
topic)]
|
||||||
(core/delete realm mailserver-topic))))
|
(core/delete realm mailserver-topic))))
|
||||||
|
|
||||||
(defn save-chat-requests-range
|
(defn save-chat-requests-range
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
(ns status-im.data-store.messages
|
(ns status-im.data-store.messages
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [clojure.set :as clojure.set]
|
||||||
[clojure.set :as clojure.set]
|
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
|
[re-frame.core :as re-frame]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
[status-im.data-store.realm.core :as core]
|
[status-im.data-store.realm.core :as core]
|
||||||
[status-im.utils.core :as utils]
|
|
||||||
[status-im.js-dependencies :as dependencies]
|
[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)]
|
(when-let [parsed-content (utils/safe-read-message-content content)]
|
||||||
(-> message
|
(-> message
|
||||||
(update :message-type keyword)
|
(update :message-type keyword)
|
||||||
|
@ -60,7 +64,7 @@
|
||||||
(keep (fn [{:keys [response-to response-to-v2]}]
|
(keep (fn [{:keys [response-to response-to-v2]}]
|
||||||
(when-let [js-message
|
(when-let [js-message
|
||||||
(if response-to-v2
|
(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/single (core/get-by-field
|
||||||
@core/account-realm
|
@core/account-realm
|
||||||
:message :old-message-id response-to)))]
|
:message :old-message-id response-to)))]
|
||||||
|
@ -124,18 +128,15 @@
|
||||||
"Returns tx function for deleting message"
|
"Returns tx function for deleting message"
|
||||||
[message-id]
|
[message-id]
|
||||||
(fn [realm]
|
(fn [realm]
|
||||||
(when-let [message (core/get-by-field realm :message :message-id message-id)]
|
(core/delete realm (get-message-by-id message-id realm))))
|
||||||
(core/delete realm message)
|
|
||||||
(core/delete realm (core/get-by-field realm :user-status :message-id message-id)))))
|
|
||||||
|
|
||||||
(defn delete-chat-messages-tx
|
(defn delete-chat-messages-tx
|
||||||
"Returns tx function for deleting messages with user statuses for given chat-id"
|
"Returns tx function for deleting messages with user statuses for given chat-id"
|
||||||
[chat-id]
|
[chat-id]
|
||||||
(fn [realm]
|
(fn [realm]
|
||||||
(core/delete realm (core/get-by-field realm :message :chat-id chat-id))
|
(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))))
|
|
||||||
|
|
||||||
(defn message-exists? [message-id]
|
(defn message-exists? [message-id]
|
||||||
(if @core/account-realm
|
(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))
|
false))
|
||||||
|
|
|
@ -41,6 +41,5 @@
|
||||||
"Returns tx function for deleting transport"
|
"Returns tx function for deleting transport"
|
||||||
[chat-id]
|
[chat-id]
|
||||||
(fn [realm]
|
(fn [realm]
|
||||||
(let [transport (core/single
|
(let [transport (.objectForPrimaryKey realm "transport" chat-id)]
|
||||||
(core/get-by-field realm :transport :chat-id chat-id))]
|
|
||||||
(core/delete realm transport))))
|
(core/delete realm transport))))
|
||||||
|
|
Loading…
Reference in New Issue