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