Skip to content

Commit 39bd579

Browse files
committed
WIP2
1 parent e8300b4 commit 39bd579

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

modules/fstore-postgres/src/hyak2/postgres_store.clj

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@
3434
(defn- feature-row->feature
3535
"Flatten an {:fkey :metadata} row into a flat map with expires-at parsed.
3636
37-
When `serialize?` is true, decodes JSON manually (instead of setting up
38-
auto-convert via next.jdbc) so we don't mess with library consumers. When
39-
false, assumes the auto-convert is in effect."
40-
[serialize? feature-row]
41-
(let [raw-meta (.getValue (:metadata feature-row))
42-
metadata (if serialize?
37+
Just decodes JSON manually (instead of setting up auto-convert via
38+
next.jdbc) so we don't mess with library consumers. "
39+
[feature-row]
40+
;; need to re-eval this, base might have futzed w the connection to de-jsonify
41+
(let [raw-meta (if (map? (:metadata feature-row))
42+
(:metadata feature-row)
43+
(.getValue (:metadata feature-row)))
44+
metadata (if (string? raw-meta)
4345
(json/read-str raw-meta :key-fn keyword)
4446
raw-meta)
4547
?expires-at (:expires-at metadata)]
@@ -177,19 +179,16 @@
177179
[f ttl-threshold-msec]
178180
(if ttl-threshold-msec (memo/ttl f :ttl/threshold ttl-threshold-msec) f))
179181

180-
(defrecord FeatureStore
181-
[table-prefix datasource enabled-pred serialize? *group-registry]
182+
(defrecord FeatureStore [table-prefix datasource enabled-pred *group-registry]
182183
ha/IFStore
183184
(-features [_]
184185
(let [params (make-names table-prefix)]
185-
(map (partial feature-row->feature serialize?)
186-
(hug:select-features datasource params))))
186+
(map feature-row->feature (hug:select-features datasource params))))
187187

188188
(-add! [_ fkey expires-at author]
189189
(let [row {:fkey fkey
190-
:metadata (cond-> {:expires-at (ldt->string expires-at)
191-
:author author}
192-
serialize? json/write-str)}
190+
:metadata (json/write-str {:expires-at (ldt->string expires-at)
191+
:author author})}
193192
params (merge (make-names table-prefix) row)]
194193
(hug:upsert-feature datasource params)))
195194

@@ -199,8 +198,7 @@
199198

200199
(-expired? [_ fkey now]
201200
(let [params (merge (make-names table-prefix) {:fkey fkey})
202-
feature (some-> (hug:select-feature datasource params)
203-
(partial feature-row->feature serialize?))]
201+
feature (some-> (hug:select-feature datasource params) feature-row->feature)]
204202
(hp/before? (:expires-at feature) now)))
205203

206204
(-disable! [_ fkey]
@@ -293,10 +291,6 @@
293291
Supply opts `{:clear-tables? true}` to reuse existing tables but clear
294292
existing table data.
295293
296-
Supply opts `{:disable-serialization? true}` to opt out of JSON
297-
serialization if the jdbc protocols have been extended to handle it
298-
automatically, eg. as outlined in https://cljdoc.org/d/seancorfield/next.jdbc/1.2.659/doc/getting-started/tips-tricks#working-with-json-and-jsonb
299-
300294
Supply opts `{:ttl/threshold msec}` to memoize the `enabled?` call to
301295
reduce db load, at the cost of the TTL's delay in a feature's activation."
302296
([table-prefix jdbc-database-url]
@@ -310,7 +304,6 @@
310304
(->FeatureStore table-prefix
311305
jdbc-database-url
312306
(memoize-fn enabled? (:ttl/threshold opts))
313-
(boolean (not (:disable-serialization? opts)))
314307
(atom {}))))
315308

316309
(defn destroy-fstore! [{:keys [table-prefix datasource] :as _fstore}]

0 commit comments

Comments
 (0)