|
79 | 79 | :tx-tail tail |
80 | 80 | :db-last-stored db})))) |
81 | 81 |
|
| 82 | +(defn ^:no-doc store-after-transact! |
| 83 | + [conn tx-report] |
| 84 | + (when-some [storage (storage/storage @conn)] |
| 85 | + (let [{db :db-after |
| 86 | + datoms :tx-data} tx-report |
| 87 | + settings (set/settings (:eavt db)) |
| 88 | + *atom (:atom conn) |
| 89 | + tx-tail' (:tx-tail (swap! *atom update :tx-tail conj datoms))] |
| 90 | + (when-not (get-in tx-report [:tx-meta :skip-store?]) |
| 91 | + (if (> (transduce (map count) + 0 tx-tail') (:branching-factor settings)) |
| 92 | + ;; overflow tail |
| 93 | + (do |
| 94 | + (storage/store-impl! db (storage/storage-adapter db) false) |
| 95 | + (swap! *atom assoc |
| 96 | + :tx-tail [] |
| 97 | + :db-last-stored db)) |
| 98 | + ;; just update tail |
| 99 | + (storage/store-tail db tx-tail')))))) |
| 100 | + |
82 | 101 | (defn ^:no-doc -transact! [conn tx-data tx-meta] |
83 | 102 | {:pre [(conn? conn)]} |
84 | 103 | (let [*report (volatile! nil) |
85 | | - skip-store? (:skip-store? tx-meta) |
86 | 104 | tx-meta' (dissoc tx-meta :skip-store?)] |
87 | 105 | (swap! conn |
88 | 106 | (fn [db] |
89 | 107 | (let [r (with db tx-data tx-meta')] |
90 | 108 | (vreset! *report r) |
91 | 109 | (:db-after r)))) |
92 | | - (when-some [storage (storage/storage @conn)] |
93 | | - (let [{db :db-after |
94 | | - datoms :tx-data} @*report |
95 | | - settings (set/settings (:eavt db)) |
96 | | - *atom (:atom conn) |
97 | | - tx-tail' (:tx-tail (swap! *atom update :tx-tail conj datoms))] |
98 | | - (when-not skip-store? |
99 | | - (if (> (transduce (map count) + 0 tx-tail') (:branching-factor settings)) |
100 | | - ;; overflow tail |
101 | | - (do |
102 | | - (storage/store-impl! db (storage/storage-adapter db) false) |
103 | | - (swap! *atom assoc |
104 | | - :tx-tail [] |
105 | | - :db-last-stored db)) |
106 | | - ;; just update tail |
107 | | - (storage/store-tail db tx-tail'))))) |
108 | | - @*report)) |
| 110 | + (let [tx-report @*report] |
| 111 | + (store-after-transact! conn tx-report) |
| 112 | + @*report))) |
| 113 | + |
| 114 | +(defn ^:no-doc run-callbacks |
| 115 | + [conn report] |
| 116 | + (doseq [[_ callback] (:listeners @(:atom conn))] |
| 117 | + (callback report))) |
109 | 118 |
|
110 | 119 | (defn transact! |
111 | 120 | ([conn tx-data] |
|
114 | 123 | {:pre [(conn? conn)]} |
115 | 124 | (locking conn |
116 | 125 | (let [report (-transact! conn tx-data tx-meta)] |
117 | | - (doseq [[_ callback] (:listeners @(:atom conn))] |
118 | | - (callback report)) |
| 126 | + (run-callbacks conn report) |
119 | 127 | report)))) |
120 | 128 |
|
121 | 129 | (defn reset-conn! |
|
141 | 149 | :tx-tail [] |
142 | 150 | :db-last-stored db)) |
143 | 151 | (reset! conn db)) |
144 | | - (doseq [[_ callback] (:listeners @(:atom conn))] |
145 | | - (callback report)) |
| 152 | + (run-callbacks conn report) |
146 | 153 | db))) |
147 | 154 |
|
148 | 155 | (defn reset-schema! [conn schema] |
|
0 commit comments