further transactions improvement.
This commit is contained in:
@@ -25,69 +25,52 @@
|
|||||||
(= (:asc args) false) (reverse)))
|
(= (:asc args) false) (reverse)))
|
||||||
|
|
||||||
(defn apply-pagination [args results]
|
(defn apply-pagination [args results]
|
||||||
(->> results
|
{:ids (->> results
|
||||||
(drop (:start args 0))
|
(drop (:start args 0))
|
||||||
(take (:count args 100))))
|
(take (:count args 100))
|
||||||
|
(map first))
|
||||||
|
:count (count results)})
|
||||||
|
|
||||||
(defn raw-graphql-ids [db args]
|
(defn raw-graphql-ids [db args]
|
||||||
(->
|
(let [query (cond-> {:query {:find (if (:sort-by args)
|
||||||
(cond-> {:query {:find (if (:sort-by args)
|
['?e '?sorter]
|
||||||
['?e '?sorter]
|
['?e])
|
||||||
['?e])
|
:in ['$ ]
|
||||||
:in ['$ ]
|
:where
|
||||||
:where
|
(condp = (:sort-by args)
|
||||||
(condp = (:sort-by args)
|
"client" ['[?e :transaction/id]
|
||||||
"client" ['[?e :transaction/id]
|
'[?e :transaction/client ?c]
|
||||||
|
'[?c :client/name ?sorter]]
|
||||||
|
|
||||||
|
nil [['?e :transaction/id]]
|
||||||
|
|
||||||
'[?e :transaction/client ?c]
|
[['?e (keyword "transaction" (:sort-by args)) '?sorter]])
|
||||||
'[?c :client/name ?sorter]]
|
}
|
||||||
|
:args [db]}
|
||||||
|
|
||||||
nil [['?e :transaction/id]]
|
(limited-clients (:id args)) (add-arg '[?xx ...] (set (map :db/id (limited-clients (:id args))))
|
||||||
|
'[?e :transaction/client ?xx])
|
||||||
[['?e (keyword "transaction" (:sort-by args)) '?sorter]]
|
(:client-id args) (add-arg '?client-id (:client-id args)
|
||||||
)
|
'[?e :transaction/client ?client-id])
|
||||||
}
|
(:original-id args) (add-arg '?original-id (cond-> (:original-id args) (string? (:original-id args)) Long/parseLong )
|
||||||
:args [db]}
|
'[?e :transaction/client ?c]
|
||||||
|
'[?c :client/original-id ?original-id]))]
|
||||||
(limited-clients (:id args)) (add-arg '[?xx ...] (set (map :db/id (limited-clients (:id args))))
|
(cond->> query
|
||||||
'[?e :transaction/client ?xx])
|
true (d/query)
|
||||||
(:client-id args) (add-arg '?client-id (:client-id args)
|
(:sort-by args) (apply-sort args second)
|
||||||
'[?e :transaction/client ?client-id])
|
true (apply-pagination args))))
|
||||||
(:original-id args) (add-arg '?original-id (cond-> (:original-id args) (string? (:original-id args)) Long/parseLong )
|
|
||||||
'[?e :transaction/client ?c]
|
|
||||||
'[?c :client/original-id ?original-id]))
|
|
||||||
|
|
||||||
(d/query)))
|
|
||||||
|
|
||||||
(defn graphql-results [ids db args]
|
(defn graphql-results [ids db args]
|
||||||
(->> (d/query
|
(->> (d/pull-many db '[* {:transaction/client [:client/name :db/id]
|
||||||
(cond-> {:query {:find ['(pull ?xx [* {:transaction/client [:client/name :db/id]
|
:transaction/bank-account [:bank-account/name :bank-account/yodlee-account-id]}]
|
||||||
:transaction/bank-account [:bank-account/name :bank-account/yodlee-account-id]}])]
|
ids)
|
||||||
:in ['$]
|
|
||||||
:where []}
|
|
||||||
:args [db]}
|
|
||||||
|
|
||||||
true (add-arg '[?xx ...] ids
|
|
||||||
'[?xx :transaction/id])))
|
|
||||||
(map first)
|
|
||||||
|
|
||||||
(map #(update % :transaction/date c/from-date))
|
(map #(update % :transaction/date c/from-date))
|
||||||
(map #(update % :transaction/post-date c/from-date))))
|
(map #(update % :transaction/post-date c/from-date))
|
||||||
|
(apply-sort args (some-> (:sort-by args) sort-fn))))
|
||||||
|
|
||||||
|
|
||||||
(defn get-graphql [args]
|
(defn get-graphql [args]
|
||||||
(let [db (d/db (d/connect uri))
|
(let [db (d/db (d/connect uri))
|
||||||
ids-to-retrieve (->> (raw-graphql-ids db args)
|
{ids-to-retrieve :ids matching-count :count} (raw-graphql-ids db args)]
|
||||||
(apply-sort args (when (:sort-by args) second)))
|
|
||||||
matching-count (count ids-to-retrieve)
|
|
||||||
ids-to-retrieve (apply-pagination args ids-to-retrieve )]
|
|
||||||
|
|
||||||
[(->> (graphql-results (map first ids-to-retrieve) db args)
|
[(->> (graphql-results ids-to-retrieve db args))
|
||||||
(apply-sort args (some-> (:sort-by args) sort-fn)))
|
|
||||||
matching-count]))
|
matching-count]))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user