|
75 | 75 | (defn ^:private transit-global-db-file [] |
76 | 76 | (io/file (global-cache-dir) "db.transit.json")) |
77 | 77 |
|
78 | | -(defn ^:private read-cache [cache-file] |
| 78 | +(defn ^:private read-cache [cache-file metrics] |
79 | 79 | (try |
80 | | - (metrics/task |
81 | | - :db/read-cache |
| 80 | + (metrics/task metrics :db/read-cache |
82 | 81 | (if (fs/exists? cache-file) |
83 | 82 | (let [cache (with-open [is (io/input-stream cache-file)] |
84 | 83 | (transit/read (transit/reader is :json)))] |
|
88 | 87 | (catch Throwable e |
89 | 88 | (logger/error logger-tag "Could not load global cache from DB" e)))) |
90 | 89 |
|
91 | | -(defn ^:private upsert-cache! [cache cache-file] |
| 90 | +(defn ^:private upsert-cache! [cache cache-file metrics] |
92 | 91 | (try |
93 | | - (metrics/task |
94 | | - :db/upsert-cache |
| 92 | + (metrics/task metrics :db/upsert-cache |
95 | 93 | (io/make-parents cache-file) |
96 | 94 | ;; https://github.com/cognitect/transit-clj/issues/43 |
97 | 95 | (with-open [os ^OutputStream (no-flush-output-stream (io/output-stream cache-file))] |
|
100 | 98 | (catch Throwable e |
101 | 99 | (logger/error logger-tag (str "Could not upsert db cache to " cache-file) e)))) |
102 | 100 |
|
103 | | -(defn ^:private read-global-cache [] |
104 | | - (let [cache (read-cache (transit-global-db-file))] |
| 101 | +(defn ^:private read-global-cache [metrics] |
| 102 | + (let [cache (read-cache (transit-global-db-file) metrics)] |
105 | 103 | (when (= version (:version cache)) |
106 | 104 | cache))) |
107 | 105 |
|
108 | | -(defn ^:private read-global-by-workspaces-cache [workspaces] |
109 | | - (let [cache (read-cache (transit-global-by-workspaces-db-file workspaces))] |
| 106 | +(defn ^:private read-global-by-workspaces-cache [workspaces metrics] |
| 107 | + (let [cache (read-cache (transit-global-by-workspaces-db-file workspaces) metrics)] |
110 | 108 | (when (= version (:version cache)) |
111 | 109 | cache))) |
112 | 110 |
|
113 | | -(defn load-db-from-cache! [db* config] |
| 111 | +(defn load-db-from-cache! [db* config metrics] |
114 | 112 | (when-not (:pureConfig config) |
115 | | - (when-let [global-cache (read-global-cache)] |
| 113 | + (when-let [global-cache (read-global-cache metrics)] |
116 | 114 | (logger/info logger-tag "Loading from global-cache caches...") |
117 | 115 | (swap! db* shared/deep-merge global-cache)) |
118 | | - (when-let [global-by-workspace-cache (read-global-by-workspaces-cache (:workspace-folders @db*))] |
| 116 | + (when-let [global-by-workspace-cache (read-global-by-workspaces-cache (:workspace-folders @db*) metrics)] |
119 | 117 | (logger/info logger-tag "Loading from workspace-cache caches...") |
120 | 118 | (swap! db* shared/deep-merge global-by-workspace-cache)))) |
121 | 119 |
|
|
130 | 128 | (defn ^:private normalize-db-for-global-write [db] |
131 | 129 | (select-keys db [:auth])) |
132 | 130 |
|
133 | | -(defn update-workspaces-cache! [db] |
| 131 | +(defn update-workspaces-cache! [db metrics] |
134 | 132 | (-> (normalize-db-for-workspace-write db) |
135 | 133 | (assoc :version version) |
136 | | - (upsert-cache! (transit-global-by-workspaces-db-file (:workspace-folders db))))) |
| 134 | + (upsert-cache! (transit-global-by-workspaces-db-file (:workspace-folders db)) metrics))) |
137 | 135 |
|
138 | | -(defn update-global-cache! [db] |
| 136 | +(defn update-global-cache! [db metrics] |
139 | 137 | (-> (normalize-db-for-global-write db) |
140 | 138 | (assoc :version version) |
141 | | - (upsert-cache! (transit-global-db-file)))) |
| 139 | + (upsert-cache! (transit-global-db-file) metrics))) |
0 commit comments