Skip to content

Commit

Permalink
fix keyword renaming performance (#17291)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkjr authored and FFFra committed Sep 15, 2023
1 parent f6ac996 commit f86483d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
40 changes: 31 additions & 9 deletions src/status_im2/contexts/communities/discover/events.cljs
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
(ns status-im2.contexts.communities.discover.events
(:require [camel-snake-kebab.core :as csk]
[clojure.string :as string]
[taoensso.timbre :as log]
(:require [taoensso.timbre :as log]
[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
[k]
(let [s (name k)
lower-cased (csk/->kebab-case-string s)
starts-with-digit? (re-matches #"^\d.*" s)
predicate? (some #(string/starts-with? lower-cased %)
["can-" "is-"])]
existing-rename (k commmunity-keys-renamed)]
(cond starts-with-digit? s
predicate? (keyword (str lower-cased "?"))
:else (keyword lower-cased))))
existing-rename existing-rename
:else (keyword s))))

(defn rename-contract-community-keys
[m]
Expand Down Expand Up @@ -43,4 +66,3 @@
:params []
:on-success #(rf/dispatch [:fetched-contract-communities %])
:on-error #(log/error "failed to fetch contract communities" %)}]})

16 changes: 6 additions & 10 deletions src/status_im2/contexts/communities/discover/events_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@

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

(deftest rename-contract-community-keys-test
(are [i e] (= (events/rename-contract-community-keys i) e)
Expand Down

0 comments on commit f86483d

Please sign in to comment.