fix keyword renaming performance (#17291)
This commit is contained in:
parent
72b8979c79
commit
4006495b22
|
@ -143,5 +143,7 @@
|
||||||
"localPairing" (handle-local-pairing-signals
|
"localPairing" (handle-local-pairing-signals
|
||||||
cofx
|
cofx
|
||||||
(js->clj event-js :keywordize-keys true))
|
(js->clj event-js :keywordize-keys true))
|
||||||
|
"curated.communities.update" (rf/dispatch [:fetched-contract-communities
|
||||||
|
(js->clj event-js :keywordize-keys true)])
|
||||||
|
|
||||||
(log/debug "Event " type " not handled"))))
|
(log/debug "Event " type " not handled"))))
|
||||||
|
|
|
@ -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" %)}]})
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,9 @@
|
||||||
|
|
||||||
(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?
|
|
||||||
:isFooBar :is-foo-bar?
|
|
||||||
:canFoo :can-foo?
|
|
||||||
:canFooBar :can-foo-bar?
|
|
||||||
:0x025d27e58 "0x025d27e58"
|
:0x025d27e58 "0x025d27e58"
|
||||||
:093b4684-92f0 "093b4684-92f0"
|
:093b4684-92f0 "093b4684-92f0"
|
||||||
:3f9e77b8-97c7 "3f9e77b8-97c7"))
|
:3f9e77b8-97c7 "3f9e77b8-97c7"))
|
||||||
|
|
Loading…
Reference in New Issue