it's okay to upsert without checking existing.
This commit is contained in:
@@ -408,19 +408,9 @@
|
|||||||
([client location]
|
([client location]
|
||||||
(lc/with-context {:source "Square settlements loading"}
|
(lc/with-context {:source "Square settlements loading"}
|
||||||
(try
|
(try
|
||||||
(let [existing (->> (d/query {:query {:find ['?external-id]
|
(doseq [x (partition-all 20 (daily-settlements client location))]
|
||||||
:in ['$ '?client]
|
(log/info "Loading expected deposit" (count x))
|
||||||
:where ['[?d :expected-deposit/client ?client]
|
@(d/transact conn x))
|
||||||
'[?d :expected-deposit/external-id ?external-id]]}
|
|
||||||
:args [(d/db conn) (:db/id client)]})
|
|
||||||
(map first)
|
|
||||||
set)
|
|
||||||
_ (log/info (count existing) "settlements already exist")
|
|
||||||
to-create (filter #(not (existing (:expected-deposit/external-id %)))
|
|
||||||
(daily-settlements client location))]
|
|
||||||
(doseq [x (partition-all 20 to-create)]
|
|
||||||
(log/info "Loading expected deposit" (count x))
|
|
||||||
@(d/transact conn x)))
|
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(log/error e)))
|
(log/error e)))
|
||||||
(log/info "Done loading settlements"))))
|
(log/info "Done loading settlements"))))
|
||||||
@@ -435,19 +425,9 @@
|
|||||||
:client (:client/code client)
|
:client (:client/code client)
|
||||||
:location (:square-location/client-location client)}
|
:location (:square-location/client-location client)}
|
||||||
(try
|
(try
|
||||||
(let [existing (->> (d/query {:query {:find ['?external-id]
|
(doseq [x (partition-all 20 (refunds client location))]
|
||||||
:in ['$ '?client]
|
(log/info "Loading refund" (count x))
|
||||||
:where ['[?r :sales-refund/client ?client]
|
@(d/transact conn x))
|
||||||
'[?r :sales-refund/external-id ?external-id]]}
|
|
||||||
:args [(d/db conn) (:db/id client)]})
|
|
||||||
(map first)
|
|
||||||
set)
|
|
||||||
_ (log/info (count existing) "refunds already exist")
|
|
||||||
to-create (filter #(not (existing (:sales-refund/external-id %)))
|
|
||||||
(refunds client location))]
|
|
||||||
(doseq [x (partition-all 20 to-create)]
|
|
||||||
(log/info "Loading refund" (count x))
|
|
||||||
@(d/transact conn x)))
|
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(log/error e)))
|
(log/error e)))
|
||||||
(log/info "Done loading refunds"))))
|
(log/info "Done loading refunds"))))
|
||||||
|
|||||||
Reference in New Issue
Block a user