From cfba7a0346221ae59f70d277bc4c0c755dd4e017 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Mon, 21 Dec 2020 19:11:48 -0800 Subject: [PATCH] Improvements to performance! --- src/clj/auto_ap/datomic/ledger.clj | 35 ++++++++++++++++-------------- src/clj/auto_ap/graphql/ledger.clj | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/clj/auto_ap/datomic/ledger.clj b/src/clj/auto_ap/datomic/ledger.clj index 3f1539f0..27773bb8 100644 --- a/src/clj/auto_ap/datomic/ledger.clj +++ b/src/clj/auto_ap/datomic/ledger.clj @@ -14,28 +14,19 @@ (let [query (cond-> {:query {:find [] :in ['$ ] - :where ['[?e :journal-entry/date ?sort-default]]} + :where []} :args [db]} - (:sort args) (add-sorter-fields {"client" ['[?e :journal-entry/client ?c] - '[?c :client/name ?sort-client]] - "date" ['[?e :journal-entry/date ?sort-date]] - "vendor" ['[?e :journal-entry/vendor ?sort-vendor]] - "amount" ['[?e :journal-entry/amount ?sort-amount]] - "external-id" ['[?e :journal-entry/external-id ?sort-external-id]] - "source" ['[?e :journal-entry/source ?sort-source]]} - args) - - (limited-clients (:id args)) - (merge-query {:query {:in ['[?xx ...]] - :where ['[?e :journal-entry/client ?xx]]} - :args [(set (map :db/id (limited-clients (:id args))))]}) - + (:client-id args) (merge-query {:query {:in ['?client-id] :where ['[?e :journal-entry/client ?client-id]]} :args [(:client-id args)]}) + + + + (:only-external args) (merge-query {:query {:where ['(not [?e :journal-entry/original-entity ])]}}) @@ -113,10 +104,22 @@ :where ['[?e :journal-entry/line-items ?li] '[?li :journal-entry-line/location ?location]]} :args [(:location args)]}) + (limited-clients (:id args)) + (merge-query {:query {:in ['[?xx ...]] + :where ['[?e :journal-entry/client ?xx]]} + :args [(set (map :db/id (limited-clients (:id args))))]}) + (:sort args) (add-sorter-fields {"client" ['[?e :journal-entry/client ?c] + '[?c :client/name ?sort-client]] + "date" ['[?e :journal-entry/date ?sort-date]] + "vendor" ['[?e :journal-entry/vendor ?sort-vendor]] + "amount" ['[?e :journal-entry/amount ?sort-amount]] + "external-id" ['[?e :journal-entry/external-id ?sort-external-id]] + "source" ['[?e :journal-entry/source ?sort-source]]} + args) true (merge-query {:query {:find ['?sort-default '?e] :where ['[?e :journal-entry/date ?sort-default]]}}))] - (->> (doto query println) + (->> (doto query log/info) (d/query) (apply-sort-3 (update args :sort conj {:sort-key "default-2" :asc true})) diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index c9ea15e3..4ca85236 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -38,7 +38,7 @@ )) ) journal-entries)] - (result->page journal-entries journal-entries-count :journal_entries args))) + (result->page journal-entries journal-entries-count :journal_entries (:filters args)))) ;; TODO a better way to do this might be to accumulate ALL credits and ALL debits, and then just do for credits: balance = credits - debits. and for debits balance = debits - credits (defn credit-account? [account]