Repository: penpot/penpot
File: frontend/src/app/main/ui/workspace/libraries.cljs (ClojureScript)

Code before:
        dependencies   (mf/with-memo [shared-libraries]
                         (into {} (map (fn [{:keys [id library-file-ids]}]
                                         [id
                                          (->> (str/split library-file-ids ",")
                                               (map #(uuid/uuid %))
                                               set)])
                                       (vals shared-libraries))))

        library-names  (mf/with-memo [shared-libraries]
                         (into {} (map (fn [{:keys [id name]}]
                                         [id name])
                                       (vals shared-libraries))))

        find-connected-to
        (mf/use-fn
         (mf/deps shared-libraries dependencies library-names)
         (fn [library-id]
           (->> dependencies
                (filter (fn [[_ v]] (contains? v library-id)))
                (map first))))

        connected-to-linked?
        (mf/use-fn
         (mf/deps linked-libraries shared-libraries dependencies)
         (fn [id]
           (contains? linked-libraries id)))


        shared-libraries
        (mf/with-memo [shared-libraries linked-libraries file-id search-term dependencies]
          (when shared-libraries
            (->> (vals shared-libraries)
                 (remove #(= (:id %) file-id))
                 (remove #(contains? linked-libraries (:id %)))
                 (filter #(matches-search (:name %) search-term))
                 (map #(assoc % :connected-to (find-connected-to (:id %))))
                 (map #(assoc % :connected-to-names (->> (:connected-to %)
                                                         (keep library-names))))
                 (sort-by (comp str/lower :name)))))




        linked-libraries
        (mf/with-memo [linked-libraries dependencies]
          (->> (vals linked-libraries)
               (map #(assoc % :connected-to (find-connected-to (:id %))))
               (map #(assoc % :connected-to-names (->> (:connected-to %)
                                                       (keep library-names))))
               (sort-by (comp str/lower :name))))


Review comment (suggestion):
This can be already resolved with using `(contains? ...` directly where it is needed
This callback looks redundant and has more dependencies that are necessary i think

Code after:
        dependencies   (mf/with-memo [shared-libraries]
                         (into {} (map (juxt :id :library-file-ids) (vals shared-libraries))))

        library-names  (mf/with-memo [shared-libraries]
                         (into {} (map (fn [{:keys [id name]}]
                                         [id name])
                                       (vals shared-libraries))))

        find-connected-to
        (mf/use-fn
         (mf/deps dependencies)
         (fn [library-id]
           (->> dependencies
                (keep (fn [[k v]] (when (contains? v library-id) k))))))

        shared-libraries
        (mf/with-memo [shared-libraries linked-libraries file-id search-term]
          (when shared-libraries
            (->> (vals shared-libraries)
                 (remove #(= (:id %) file-id))
                 (remove #(contains? linked-libraries (:id %)))
                 (filter #(matches-search (:name %) search-term))
                 (map #(assoc % :connected-to (find-connected-to (:id %))))
                 (map #(assoc % :connected-to-names (->> (:connected-to %)
                                                         (keep library-names))))
                 (sort-by (comp str/lower :name)))))

        linked-libraries
        (mf/with-memo [linked-libraries find-connected-to library-names]
          (->> (vals linked-libraries)
               (map #(assoc % :connected-to (find-connected-to (:id %))))
               (map #(assoc % :connected-to-names (->> (:connected-to %)
                                                       (keep library-names))))
               (sort-by (comp str/lower :name))))

        linked-libraries-ids (mf/with-memo [linked-libraries]
                               (into #{} (map :id) linked-libraries))


        importing*       (mf/use-state nil)
        sample-libraries [{:id "penpot-design-system", :name "Design system example"}
                          {:id "wireframing-kit", :name "Wireframe library"}
                          {:id "whiteboarding-kit", :name "Whiteboarding Kit"}]


        change-search-term
        (mf/use-fn
         (fn [event]
           (reset! search-term* event)))

        link-library