|
5 | 5 | [environ.core :refer [env]]
|
6 | 6 | [datahike.tools :as tools]
|
7 | 7 | [datahike.store :as ds]
|
8 |
| - [datahike.constants :as c]) |
| 8 | + [datahike.index :as di]) |
9 | 9 | (:import [java.net URI]))
|
10 | 10 |
|
| 11 | +(def ^:dynamic default-index :datahike.index/persistent-set) |
| 12 | +(def ^:dynamic default-search-cache-size 10000) |
| 13 | +(def ^:dynamic default-store-cache-size 1000) |
| 14 | + |
11 | 15 | (s/def ::index #{:datahike.index/hitchhiker-tree :datahike.index/persistent-set})
|
12 | 16 | (s/def ::keep-history? boolean?)
|
13 | 17 | (s/def ::schema-flexibility #{:read :write})
|
14 | 18 | (s/def ::attribute-refs? boolean?)
|
| 19 | +(s/def ::search-cache-size nat-int?) |
| 20 | +(s/def ::store-cache-size pos-int?) |
| 21 | +(s/def ::crypto-hash? boolean?) |
15 | 22 | (s/def ::entity (s/or :map associative? :vec vector?))
|
16 | 23 | (s/def ::initial-tx (s/nilable (s/or :data (s/coll-of ::entity) :path string?)))
|
17 | 24 | (s/def ::name string?)
|
|
32 | 39 | ::keep-history?
|
33 | 40 | ::schema-flexibility
|
34 | 41 | ::attribute-refs?
|
| 42 | + ::search-cache-size |
| 43 | + ::store-cache-size |
| 44 | + ::crypto-hash? |
35 | 45 | ::initial-tx
|
36 | 46 | ::name
|
37 | 47 | ::middleware]))
|
|
42 | 52 | :opt-un [:deprecated/temporal-index :deprecated/schema-on-read]))
|
43 | 53 |
|
44 | 54 | (defn from-deprecated
|
45 |
| - [{:keys [backend username password path host port] :as backend-cfg} |
| 55 | + [{:keys [backend username password path host port] :as _backend-cfg} |
46 | 56 | & {:keys [schema-on-read temporal-index index initial-tx]
|
47 |
| - :as index-cfg |
| 57 | + :as _index-cfg |
48 | 58 | :or {schema-on-read false
|
49 | 59 | index :datahike.index/hitchhiker-tree
|
50 | 60 | temporal-index true}}]
|
|
60 | 70 | :level {:path path}
|
61 | 71 | :file {:path path}))
|
62 | 72 | :index index
|
63 |
| - :index-config {:index-b-factor c/default-index-b-factor |
64 |
| - :index-log-size c/default-index-log-size |
65 |
| - :index-data-node-size c/default-index-data-node-size} |
| 73 | + :index-config (di/default-index-config index) |
66 | 74 | :keep-history? temporal-index
|
67 | 75 | :attribute-refs? false
|
68 | 76 | :initial-tx initial-tx
|
69 | 77 | :schema-flexibility (if (true? schema-on-read) :read :write)
|
70 |
| - :cache-size 100000}) |
| 78 | + :crypto-hash? false |
| 79 | + :search-cache-size default-search-cache-size |
| 80 | + :store-cache-size default-store-cache-size}) |
71 | 81 |
|
72 | 82 | (defn int-from-env
|
73 | 83 | [key default]
|
|
104 | 114 | :schema-flexibility :read
|
105 | 115 | :name (z/rand-german-mammal)
|
106 | 116 | :attribute-refs? false
|
107 |
| - :index :datahike.index/hitchhiker-tree |
108 |
| - :cache-size 100000 |
109 |
| - :index-config {:index-b-factor c/default-index-b-factor |
110 |
| - :index-log-size c/default-index-log-size |
111 |
| - :index-data-node-size c/default-index-data-node-size}}) |
| 117 | + :index default-index |
| 118 | + :search-cache-size default-search-cache-size |
| 119 | + :store-cache-size default-store-cache-size |
| 120 | + :crypto-hash? false |
| 121 | + :index-config (di/default-index-config default-index)}) |
112 | 122 |
|
113 | 123 | (defn remove-nils
|
114 | 124 | "Thanks to https://stackoverflow.com/a/34221816"
|
|
133 | 143 | store-config (ds/default-config (merge
|
134 | 144 | {:backend (keyword (:datahike-store-backend env :mem))}
|
135 | 145 | (:store config-as-arg)))
|
| 146 | + index (if (:datahike-index env) |
| 147 | + (keyword "datahike.index" (:datahike-index env)) |
| 148 | + default-index) |
136 | 149 | config {:store store-config
|
137 | 150 | :initial-tx (:datahike-intial-tx env)
|
138 | 151 | :keep-history? (bool-from-env :datahike-keep-history true)
|
139 | 152 | :attribute-refs? (bool-from-env :datahike-attribute-refs false)
|
140 | 153 | :name (:datahike-name env (z/rand-german-mammal))
|
141 | 154 | :schema-flexibility (keyword (:datahike-schema-flexibility env :write))
|
142 |
| - :index (keyword "datahike.index" (:datahike-index env "hitchhiker-tree")) |
143 |
| - :cache-size (:cache-size env 100000) |
144 |
| - :index-config {:index-b-factor (int-from-env :datahike-b-factor c/default-index-b-factor) |
145 |
| - :index-log-size (int-from-env :datahike-log-size c/default-index-log-size) |
146 |
| - :index-data-node-size (int-from-env :datahike-data-node-size c/default-index-data-node-size)}} |
| 155 | + :index index |
| 156 | + :crypto-hash? false |
| 157 | + :search-cache-size (int-from-env :datahike-search-cache-size default-search-cache-size) |
| 158 | + :store-cache-size (int-from-env :datahike-store-cache-size default-store-cache-size) |
| 159 | + :index-config (if-let [index-config (map-from-env :datahike-index-config nil)] |
| 160 | + index-config |
| 161 | + (di/default-index-config index))} |
147 | 162 | merged-config ((comp remove-nils tools/deep-merge) config config-as-arg)
|
148 | 163 | {:keys [schema-flexibility initial-tx store attribute-refs?]} merged-config
|
149 | 164 | config-spec (ds/config-spec store)]
|
|
0 commit comments