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