Fixing export bugs with bad queries, improving performance.
This commit is contained in:
@@ -792,15 +792,18 @@
|
|||||||
|
|
||||||
(defn apply-sort-3 [args results]
|
(defn apply-sort-3 [args results]
|
||||||
(let [sort-bys (or (:sort args) [])
|
(let [sort-bys (or (:sort args) [])
|
||||||
|
length (count sort-bys)
|
||||||
comparator (fn [xs ys]
|
comparator (fn [xs ys]
|
||||||
(or (->> (map vector sort-bys xs ys)
|
(reduce
|
||||||
(map (fn [[{:keys [asc]} x y]]
|
(fn [_ i]
|
||||||
(if asc
|
(let [comparison (if (:asc (sort-bys i))
|
||||||
(compare x y)
|
(compare (nth xs i) (nth ys i))
|
||||||
(compare y x))))
|
(compare (nth ys i) (nth xs i)))]
|
||||||
(drop-while #(= 0 %))
|
(if (not= 0 comparison)
|
||||||
first)
|
(reduced comparison)
|
||||||
0))]
|
0)))
|
||||||
|
0
|
||||||
|
(range length)))]
|
||||||
(sort comparator results )))
|
(sort comparator results )))
|
||||||
|
|
||||||
(defn apply-pagination [args results]
|
(defn apply-pagination [args results]
|
||||||
|
|||||||
@@ -28,19 +28,7 @@
|
|||||||
:in ['$]
|
:in ['$]
|
||||||
:where ['[?e :invoice/invoice-number]]}
|
:where ['[?e :invoice/invoice-number]]}
|
||||||
:args [(d/db (d/connect uri))]}
|
: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))
|
(limited-clients (:id args))
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
:where ['[?e :invoice/client ?xx]]}
|
:where ['[?e :invoice/client ?xx]]}
|
||||||
@@ -92,9 +80,23 @@
|
|||||||
:where ['[?e :invoice/invoice-number ?invoice-number]
|
:where ['[?e :invoice/invoice-number ?invoice-number]
|
||||||
'[(.contains ^String ?invoice-number ?invoice-number-like)]]}
|
'[(.contains ^String ?invoice-number ?invoice-number-like)]]}
|
||||||
:args [(:invoice-number-like args)]})
|
: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
|
true
|
||||||
(merge-query {:query {:find ['?base-date '?e]
|
(merge-query {:query {:find ['?e]
|
||||||
:where ['[?e :invoice/date ?base-date]]}}) )
|
:where ['[?e :invoice/client]]}}) )
|
||||||
(d/query)
|
(d/query)
|
||||||
(apply-sort-3 args)
|
(apply-sort-3 args)
|
||||||
(apply-pagination args)))
|
(apply-pagination args)))
|
||||||
|
|||||||
@@ -25,25 +25,7 @@
|
|||||||
:where []}
|
:where []}
|
||||||
:args [db]}
|
: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))
|
(limited-clients (:id args))
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
@@ -113,9 +95,28 @@
|
|||||||
'[(.contains ?do ?description)]]}
|
'[(.contains ?do ?description)]]}
|
||||||
:args [(:description args)]})
|
: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
|
true
|
||||||
(merge-query {:query {:find ['?base-date '?e] :where ['[?e :transaction/id]
|
(merge-query {:query {:find ['?e] :where ['[?e :transaction/id]]}}))
|
||||||
'[?e :transaction/date ?base-date]]}}))]
|
_ (println query)]
|
||||||
(cond->> query
|
(cond->> query
|
||||||
true (d/query)
|
true (d/query)
|
||||||
true (apply-sort-3 args)
|
true (apply-sort-3 args)
|
||||||
|
|||||||
@@ -784,7 +784,7 @@
|
|||||||
(assert-admin (:id context))
|
(assert-admin (:id context))
|
||||||
(map
|
(map
|
||||||
->graphql
|
->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]
|
(defn get-user [context args value]
|
||||||
|
|||||||
@@ -28,8 +28,8 @@
|
|||||||
(assert-admin (:id context))
|
(assert-admin (:id context))
|
||||||
(map
|
(map
|
||||||
->graphql
|
->graphql
|
||||||
(d-invoices/get-graphql (assoc (<-graphql args)
|
(first (d-invoices/get-graphql (assoc (<-graphql args)
|
||||||
:count Integer/MAX_VALUE))))
|
:count Integer/MAX_VALUE)))))
|
||||||
|
|
||||||
(defn reject-invoices [context {:keys [invoices] :as in} value]
|
(defn reject-invoices [context {:keys [invoices] :as in} value]
|
||||||
(assert-admin (:id context))
|
(assert-admin (:id context))
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
(let [query [[:all_invoices
|
(let [query [[:all_invoices
|
||||||
{:client-code (query-params "client-code")
|
{:client-code (query-params "client-code")
|
||||||
:original-id (query-params "original")}
|
:original-id (query-params "original")}
|
||||||
|
|
||||||
[:id :total :outstanding-balance :invoice-number :date :status :original-id
|
[: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]]]]]]
|
[: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]]]]
|
[:vendor [:name :id [:primary_contact [:name]] [:address [:street1 :city :state :zip]]]]
|
||||||
|
|||||||
Reference in New Issue
Block a user