fix keyword renaming performance (#17291)

This commit is contained in:
Volodymyr Kozieiev 2023-09-15 12:02:44 +01:00 committed by GitHub
parent 72b8979c79
commit 4006495b22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 63 deletions

View File

@ -96,52 +96,54 @@
^js event-js (.-event data) ^js event-js (.-event data)
type (.-type data)] type (.-type data)]
(case type (case type
"node.login" (profile.login/login-node-signal cofx (transforms/js->clj event-js)) "node.login" (profile.login/login-node-signal cofx (transforms/js->clj event-js))
"backup.performed" {:db (assoc-in db "backup.performed" {:db (assoc-in db
[:profile/profile :last-backup] [:profile/profile :last-backup]
(.-lastBackup event-js))} (.-lastBackup event-js))}
"envelope.sent" (transport.message/update-envelopes-status cofx "envelope.sent" (transport.message/update-envelopes-status cofx
(:ids (:ids
(js->clj event-js
:keywordize-keys
true))
:sent)
"envelope.expired" (transport.message/update-envelopes-status cofx
(:ids
(js->clj event-js
:keywordize-keys
true))
:not-sent)
"message.delivered" (let [{:keys [chatID messageID]} (js->clj event-js
:keywordize-keys
true)]
(models.message/update-db-message-status cofx
chatID
messageID
:delivered))
"mailserver.changed" (mailserver/handle-mailserver-changed cofx (.-id event-js))
"mailserver.available" (mailserver/handle-mailserver-available cofx (.-id event-js))
"mailserver.not.working" (mailserver/handle-mailserver-not-working cofx)
"discovery.summary" (summary cofx (js->clj event-js :keywordize-keys true))
"mediaserver.started" {:db (assoc db :mediaserver/port (.-port event-js))}
"wakuv2.peerstats" (wakuv2-peer-stats cofx (js->clj event-js :keywordize-keys true))
"messages.new" (transport.message/sanitize-messages-and-process-response cofx
event-js
true)
"wallet" (ethereum.subscriptions/new-wallet-event cofx
(js->clj event-js (js->clj event-js
:keywordize-keys :keywordize-keys
true)) true))
:sent) "local-notifications" (local-notifications/process cofx
"envelope.expired" (transport.message/update-envelopes-status cofx (js->clj event-js :keywordize-keys true))
(:ids "community.found" (link-preview/cache-community-preview-data (js->clj event-js
(js->clj event-js :keywordize-keys
:keywordize-keys true))
true)) "status.updates.timedout" (visibility-status-updates/handle-visibility-status-updates
:not-sent) cofx
"message.delivered" (let [{:keys [chatID messageID]} (js->clj event-js (js->clj event-js :keywordize-keys true))
:keywordize-keys "localPairing" (handle-local-pairing-signals
true)] cofx
(models.message/update-db-message-status cofx (js->clj event-js :keywordize-keys true))
chatID "curated.communities.update" (rf/dispatch [:fetched-contract-communities
messageID (js->clj event-js :keywordize-keys true)])
:delivered))
"mailserver.changed" (mailserver/handle-mailserver-changed cofx (.-id event-js))
"mailserver.available" (mailserver/handle-mailserver-available cofx (.-id event-js))
"mailserver.not.working" (mailserver/handle-mailserver-not-working cofx)
"discovery.summary" (summary cofx (js->clj event-js :keywordize-keys true))
"mediaserver.started" {:db (assoc db :mediaserver/port (.-port event-js))}
"wakuv2.peerstats" (wakuv2-peer-stats cofx (js->clj event-js :keywordize-keys true))
"messages.new" (transport.message/sanitize-messages-and-process-response cofx
event-js
true)
"wallet" (ethereum.subscriptions/new-wallet-event cofx
(js->clj event-js
:keywordize-keys
true))
"local-notifications" (local-notifications/process cofx
(js->clj event-js :keywordize-keys true))
"community.found" (link-preview/cache-community-preview-data (js->clj event-js
:keywordize-keys
true))
"status.updates.timedout" (visibility-status-updates/handle-visibility-status-updates
cofx
(js->clj event-js :keywordize-keys true))
"localPairing" (handle-local-pairing-signals
cofx
(js->clj event-js :keywordize-keys true))
(log/debug "Event " type " not handled")))) (log/debug "Event " type " not handled"))))

View File

@ -1,19 +1,42 @@
(ns status-im2.contexts.communities.discover.events (ns status-im2.contexts.communities.discover.events
(:require [camel-snake-kebab.core :as csk] (:require [taoensso.timbre :as log]
[clojure.string :as string]
[taoensso.timbre :as log]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(def commmunity-keys-renamed
{:requestedAccessAt :requested-access-at
:fileSize :file-size
:communityTokensMetadata :community-tokens-metadata
:activeMembersCount :active-members-count
:unknownCommunities :unknown-communities
:canRequestAccess :can-request-access?
:adminSettings :admin-settings
:canManageUsers :can-manage-users?
:categoryID :category-id
:canPost :can-post?
:isControlNode :is-control-node?
:pinMessageAllMembersEnabled :pin-message-all-members-enabled
:isMember :is-member?
:canDeleteMessageForEveryone :can-delete-message-for-everyone?
:tokenPermissions :token-permissions
:muteTill :mute-till
:contractCommunities :contract-communities
:banList :ban-list
:keyUid :key-uid
:memberRole :member-role
:introMessage :intro-message
:contractFeaturedCommunities :contract-featured-communities
:canJoin :can-join?
:outroMessage :outro-message
:resizeTarget :resize-target})
(defn rename-contract-community-key (defn rename-contract-community-key
[k] [k]
(let [s (name k) (let [s (name k)
lower-cased (csk/->kebab-case-string s)
starts-with-digit? (re-matches #"^\d.*" s) starts-with-digit? (re-matches #"^\d.*" s)
predicate? (some #(string/starts-with? lower-cased %) existing-rename (k commmunity-keys-renamed)]
["can-" "is-"])]
(cond starts-with-digit? s (cond starts-with-digit? s
predicate? (keyword (str lower-cased "?")) existing-rename existing-rename
:else (keyword lower-cased)))) :else (keyword s))))
(defn rename-contract-community-keys (defn rename-contract-community-keys
[m] [m]
@ -43,4 +66,3 @@
:params [] :params []
:on-success #(rf/dispatch [:fetched-contract-communities %]) :on-success #(rf/dispatch [:fetched-contract-communities %])
:on-error #(log/error "failed to fetch contract communities" %)}]}) :on-error #(log/error "failed to fetch contract communities" %)}]})

View File

@ -4,16 +4,12 @@
(deftest rename-contract-community-key-test (deftest rename-contract-community-key-test
(are [i e] (= (events/rename-contract-community-key i) e) (are [i e] (= (events/rename-contract-community-key i) e)
:foo :foo :requestedAccessAt :requested-access-at
:fooBar :foo-bar :canDeleteMessageForEveryone :can-delete-message-for-everyone?
:fooBarBaz :foo-bar-baz :name :name
:isFoo :is-foo? :0x025d27e58 "0x025d27e58"
:isFooBar :is-foo-bar? :093b4684-92f0 "093b4684-92f0"
:canFoo :can-foo? :3f9e77b8-97c7 "3f9e77b8-97c7"))
:canFooBar :can-foo-bar?
:0x025d27e58 "0x025d27e58"
:093b4684-92f0 "093b4684-92f0"
:3f9e77b8-97c7 "3f9e77b8-97c7"))
(deftest rename-contract-community-keys-test (deftest rename-contract-community-keys-test
(are [i e] (= (events/rename-contract-community-keys i) e) (are [i e] (= (events/rename-contract-community-keys i) e)