mirror of
https://github.com/penpot/penpot.git
synced 2026-11-05 01:20:38 +00:00
🐛 Fix library telemetry counters (#12787)
At some point the code around this changed, I believe this used to reduce over file ids. However today it reduces over entire library maps, so it passes a map instead of an id to `dm/get-in files`. This then hashes the library which forces it to decode all of its shapes, and then it fails to lookup the data. So the component/colors/typography counts were always returning 0. Using reduce-kv fixes this, and we can just get the library data directly with `(:data library)`. On the backstage file in penpot-files this brings the time to the telemetry snapshot down from 3.8s to 1.5s AI-assisted-by: claude-5.5-sonnet Co-authored-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
parent
4173cc34ab
commit
a089f7a5a1
@ -8,7 +8,6 @@
|
||||
(:require
|
||||
["@penpot/ua-parser" :as ua]
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.json :as json]
|
||||
[app.common.logging :as l]
|
||||
[app.common.math :as math]
|
||||
@ -316,14 +315,14 @@
|
||||
0)))
|
||||
|
||||
(add-libraries-counters [state files]
|
||||
(reduce (fn [state library-id]
|
||||
(let [data (dm/get-in files [library-id :data])]
|
||||
(-> state
|
||||
(update :total-components + (count (:components data)))
|
||||
(update :total-colors + (count (:colors data)))
|
||||
(update :total-typographies + (count (:typographies data))))))
|
||||
state
|
||||
(refs/select-libraries files file-id)))]
|
||||
(reduce-kv (fn [state _ library]
|
||||
(let [data (:data library)]
|
||||
(-> state
|
||||
(update :total-components + (count (:components data)))
|
||||
(update :total-colors + (count (:colors data)))
|
||||
(update :total-typographies + (count (:typographies data))))))
|
||||
state
|
||||
(refs/select-libraries files file-id)))]
|
||||
|
||||
(ptk/reify ::snapshot-performance-info
|
||||
ptk/UpdateEvent
|
||||
|
||||
@ -6,12 +6,14 @@
|
||||
|
||||
(ns frontend-tests.data.event-test
|
||||
(:require
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.event :as ev]
|
||||
[app.main.repo :as rp]
|
||||
[beicon.v2.core :as rx]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[frontend-tests.helpers.async :as async]
|
||||
[frontend-tests.helpers.mock :as mock]))
|
||||
[frontend-tests.helpers.mock :as mock]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(t/deftest events-enabled?-truth-table
|
||||
(t/testing "enabled when audit-log is present"
|
||||
@ -41,3 +43,39 @@
|
||||
{rp/cmd! (mock/stub (fn [_cmd] (rx/throw (ex-info "boom" {}))))}
|
||||
(await (async/->promise (ev/fetch-environment-data)))))]
|
||||
(t/is (= {:flags #{:telemetry}} data))))
|
||||
|
||||
(t/deftest snapshot-performance-info-counts-libraries
|
||||
(let [file-id (uuid/next)
|
||||
lib-id (uuid/next)
|
||||
other-id (uuid/next)
|
||||
unlinked (uuid/next)
|
||||
sized (fn [n] (zipmap (repeatedly n uuid/next) (repeat {})))
|
||||
data (fn [components colors typographies]
|
||||
{:components (sized components)
|
||||
:colors (sized colors)
|
||||
:typographies (sized typographies)})
|
||||
state {:files
|
||||
{file-id {:id file-id
|
||||
:data (-> (data 1 1 1)
|
||||
(assoc :pages-index (zipmap (repeatedly 2 uuid/next)
|
||||
[{:objects (sized 4)}
|
||||
{:objects (sized 2)}])))}
|
||||
lib-id {:id lib-id
|
||||
:library-of file-id
|
||||
:data (data 2 3 1)}
|
||||
other-id {:id other-id
|
||||
:library-of file-id
|
||||
:data (data 1 2 2)}
|
||||
unlinked {:id unlinked
|
||||
:library-of (uuid/next)
|
||||
:data (data 3 3 3)}}}
|
||||
state' (ptk/update (#'ev/snapshot-performance-info {:file-id file-id}) state)
|
||||
counters (get-in state' [:performance-info :counters])]
|
||||
|
||||
(t/testing "counts shapes of the current file"
|
||||
(t/is (= 6 (:total-shapes counters))))
|
||||
|
||||
(t/testing "sums the data of the file and its libraries, not other files"
|
||||
(t/is (= 4 (:total-components counters)))
|
||||
(t/is (= 6 (:total-colors counters)))
|
||||
(t/is (= 4 (:total-typographies counters))))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user