Fixing export bugs with bad queries, improving performance.

This commit is contained in:
Bryce Covert
2020-04-26 08:20:07 -07:00
parent d799fc469d
commit b89b4a86c5
6 changed files with 54 additions and 47 deletions

View File

@@ -792,15 +792,18 @@
(defn apply-sort-3 [args results]
(let [sort-bys (or (:sort args) [])
length (count sort-bys)
comparator (fn [xs ys]
(or (->> (map vector sort-bys xs ys)
(map (fn [[{:keys [asc]} x y]]
(if asc
(compare x y)
(compare y x))))
(drop-while #(= 0 %))
first)
0))]
(reduce
(fn [_ i]
(let [comparison (if (:asc (sort-bys i))
(compare (nth xs i) (nth ys i))
(compare (nth ys i) (nth xs i)))]
(if (not= 0 comparison)
(reduced comparison)
0)))
0
(range length)))]
(sort comparator results )))
(defn apply-pagination [args results]

View File

@@ -28,19 +28,7 @@
:in ['$]
:where ['[?e :invoice/invoice-number]]}
:args [(d/db (d/connect uri))]}
(:sort args) (add-sorter-fields {"client" ['[?e :invoice/client ?c]
'[?c :client/name ?sort-client]]
"vendor" ['[?e :invoice/vendor ?v]
'[?v :vendor/name ?sort-vendor]]
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
"location" ['[?e :invoice/expense-accounts ?iea]
'[?iea :invoice-expense-account/location ?sort-location]]
"date" ['[?e :invoice/date ?sort-date]]
"due" ['[?e :invoice/due ?sort-due]]
"invoice-number" ['[?e :invoice/invoice-number ?sort-invoice-number]]
"total" ['[?e :invoice/total ?sort-total]]
"outstanding-balance" ['[?e :invoice/outstanding-balance ?sort-outstanding-balance]]}
args)
(limited-clients (:id args))
(merge-query {:query {:in ['[?xx ...]]
:where ['[?e :invoice/client ?xx]]}
@@ -92,9 +80,23 @@
:where ['[?e :invoice/invoice-number ?invoice-number]
'[(.contains ^String ?invoice-number ?invoice-number-like)]]}
:args [(:invoice-number-like args)]})
(:sort args) (add-sorter-fields {"client" ['[?e :invoice/client ?c]
'[?c :client/name ?sort-client]]
"vendor" ['[?e :invoice/vendor ?v]
'[?v :vendor/name ?sort-vendor]]
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
"location" ['[?e :invoice/expense-accounts ?iea]
'[?iea :invoice-expense-account/location ?sort-location]]
"date" ['[?e :invoice/date ?sort-date]]
"due" ['[?e :invoice/due ?sort-due]]
"invoice-number" ['[?e :invoice/invoice-number ?sort-invoice-number]]
"total" ['[?e :invoice/total ?sort-total]]
"outstanding-balance" ['[?e :invoice/outstanding-balance ?sort-outstanding-balance]]}
args)
true
(merge-query {:query {:find ['?base-date '?e]
:where ['[?e :invoice/date ?base-date]]}}) )
(merge-query {:query {:find ['?e]
:where ['[?e :invoice/client]]}}) )
(d/query)
(apply-sort-3 args)
(apply-pagination args)))

View File

@@ -25,25 +25,7 @@
:where []}
:args [db]}
(:sort args) (add-sorter-fields {"client" ['[?e :transaction/client ?c]
'[?c :client/name ?sort-client]]
"account" ['[?e :transaction/date]
'(or-join [?e ?sort-account]
(and [?e :transaction/account ?c]
[?c :account/name ?sort-account])
(and
(not [?e :transaction/account])
[(ground "") ?sort-account]))]
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
"date" ['[?e :transaction/date ?sort-date]]
"vendor" ['(or-join [?e ?sort-vendor]
(and [(missing? $ ?e :transaction/vendor)]
[?e :transaction/description-original ?sort-vendor])
(and [?e :transaction/vendor ?v]
[?v :vendor/name ?sort-vendor]))]
"amount" ['[?e :transaction/amount ?sort-amount]]
"status" ['[?e :transaction/status ?sort-status]]}
args)
(limited-clients (:id args))
(merge-query {:query {:in ['[?xx ...]]
@@ -113,9 +95,28 @@
'[(.contains ?do ?description)]]}
:args [(:description args)]})
(:sort args) (add-sorter-fields {"client" ['[?e :transaction/client ?c]
'[?c :client/name ?sort-client]]
"account" ['[?e :transaction/date]
'(or-join [?e ?sort-account]
(and [?e :transaction/account ?c]
[?c :account/name ?sort-account])
(and
(not [?e :transaction/account])
[(ground "") ?sort-account]))]
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
"date" ['[?e :transaction/date ?sort-date]]
"vendor" ['(or-join [?e ?sort-vendor]
(and [(missing? $ ?e :transaction/vendor)]
[?e :transaction/description-original ?sort-vendor])
(and [?e :transaction/vendor ?v]
[?v :vendor/name ?sort-vendor]))]
"amount" ['[?e :transaction/amount ?sort-amount]]
"status" ['[?e :transaction/status ?sort-status]]}
args)
true
(merge-query {:query {:find ['?base-date '?e] :where ['[?e :transaction/id]
'[?e :transaction/date ?base-date]]}}))]
(merge-query {:query {:find ['?e] :where ['[?e :transaction/id]]}}))
_ (println query)]
(cond->> query
true (d/query)
true (apply-sort-3 args)

View File

@@ -784,7 +784,7 @@
(assert-admin (:id context))
(map
->graphql
(d-checks/get-graphql (assoc (<-graphql args) :count Integer/MAX_VALUE))))
(first (d-checks/get-graphql (assoc (<-graphql args) :count Integer/MAX_VALUE)))))
(defn get-user [context args value]

View File

@@ -28,8 +28,8 @@
(assert-admin (:id context))
(map
->graphql
(d-invoices/get-graphql (assoc (<-graphql args)
:count Integer/MAX_VALUE))))
(first (d-invoices/get-graphql (assoc (<-graphql args)
:count Integer/MAX_VALUE)))))
(defn reject-invoices [context {:keys [invoices] :as in} value]
(assert-admin (:id context))

View File

@@ -24,6 +24,7 @@
(let [query [[:all_invoices
{:client-code (query-params "client-code")
:original-id (query-params "original")}
[:id :total :outstanding-balance :invoice-number :date :status :original-id
[:payments [:amount [:payment [:check-number :memo [:bank_account [:id :name :number :bank-name :bank-code :code]]]]]]
[:vendor [:name :id [:primary_contact [:name]] [:address [:street1 :city :state :zip]]]]