;; This buffer is for Clojure experiments and evaluation. ;; Press C-j to evaluate the last expression. ;; You can also press C-u C-j to evaluate the expression and pretty-print its result. '{:query , :phases [{:sched (([(ground $__in__2) ?start-date] [?e :invoice/date ?date] [(>= ?date ?start-date)] [(ground $__in__3) [?xx ...]] [?e :invoice/client ?xx] [?e :invoice/client] [?e :invoice/date ?sort-default])), :clauses [{:clause [(ground $__in__2) ?start-date], :rows-in 0, :rows-out 1, :binds-in (), :binds-out [?start-date], :expansion 1} {:clause [?e :invoice/date ?date], :rows-in 1, :rows-out 9656, :binds-in [?start-date], :binds-out [?date ?start-date ?e], :preds ([(>= ?date ?start-date)]), :expansion 9655, :warnings {:unbound-vars #{?date ?e}}} {:clause [(ground $__in__3) [?xx ...]], :rows-in 9656, :rows-out 1303560, :binds-in [?date ?start-date ?e], :binds-out [?xx ?e], :expansion 1293904} {:clause [?e :invoice/client ?xx], :rows-in 1303560, :rows-out 9656, :binds-in [?xx ?e], :binds-out [?e]} {:clause [?e :invoice/client], :rows-in 9656, :rows-out 9656, :binds-in [?e], :binds-out [?e]} {:clause [?e :invoice/date ?sort-default], :rows-in 9656, :rows-out 9656, :binds-in [?e], :binds-out [?sort-default ?e]}]}]} ;; => {:query ;; {:find [?sort-default ?e], ;; :in [$ ?start-date [?xx ...]], ;; :where ;; [[?e :invoice/date ?date] ;; [(>= ?date ?start-date)] ;; [?e :invoice/client ?xx] ;; [?e :invoice/client] ;; [?e :invoice/date ?sort-default]]}, ;; :phases ;; [{:sched ;; (([(ground $__in__2) ?start-date] ;; [?e :invoice/date ?date] ;; [(>= ?date ?start-date)] ;; [(ground $__in__3) [?xx ...]] ;; [?e :invoice/client ?xx] ;; [?e :invoice/client] ;; [?e :invoice/date ?sort-default])), ;; :clauses ;; [{:clause [(ground $__in__2) ?start-date], ;; :rows-in 0, ;; :rows-out 1, ;; :binds-in (), ;; :binds-out [?start-date], ;; :expansion 1} ;; {:clause [?e :invoice/date ?date], ;; :rows-in 1, ;; :rows-out 9656, ;; :binds-in [?start-date], ;; :binds-out [?date ?start-date ?e], ;; :preds ([(>= ?date ?start-date)]), ;; :expansion 9655, ;; :warnings {:unbound-vars #{?date ?e}}} ;; {:clause [(ground $__in__3) [?xx ...]], ;; :rows-in 9656, ;; :rows-out 1303560, ;; :binds-in [?date ?start-date ?e], ;; :binds-out [?xx ?e], ;; :expansion 1293904} ;; {:clause [?e :invoice/client ?xx], ;; :rows-in 1303560, ;; :rows-out 9656, ;; :binds-in [?xx ?e], ;; :binds-out [?e]} ;; {:clause [?e :invoice/client], ;; :rows-in 9656, ;; :rows-out 9656, ;; :binds-in [?e], ;; :binds-out [?e]} ;; {:clause [?e :invoice/date ?sort-default], ;; :rows-in 9656, ;; :rows-out 9656, ;; :binds-in [?e], ;; :binds-out [?sort-default ?e]}]}]} (time (count (observable-query {:query {:find '[?sort-default ?e], :in '[$ [?xx ...]], :where '[[(untuple ?xx) [?target-date ?target-client]] [(tuple #inst "2030-01-01" ?target-client) ?xx2] [?e :invoice/date+client ?dc] #_[(untuple)] [(>= ?dc ?xx)] [(<= ?dc ?xx2)] [(untuple ?dc) [?sort-default]] #_[?e :invoice/date ?date] #_[(>= ?date ?start-date)] #_[?e :invoice/client ?xx] #_[?e :invoice/date ?sort-default]]} :args [(dc/db conn) g]}))) (defn recent-invoices [clients start end] (for [ c clients r (seq (dc/index-range (dc/db conn) :invoice/client+date [c (or start #inst "2001-01-01T08:00:00.000-00:00") ] [c (or end #inst "2030-03-05T08:00:00.000-00:00") ]))] (:e r))) (recent-invoices all-clients #inst "2023-03-05T08:00:00.000-00:00" #inst "2050-03-05T08:00:00.000-00:00") (count (dc/query {:query '[:find ?e :in $ [?clients ?start ?end] :where [(auto-ap.datomic.invoices/recent-invoices ?clients ?start ?end) [?e ...]]] :args [(dc/db conn) [all-clients #inst "2023-03-05T08:00:00.000-00:00" nil]]} )) (time (count (for [ c all-clients r (seq (dc/index-range (dc/db conn) :invoice/client+date [c #inst "2023-03-05T08:00:00.000-00:00" ] [c #inst "2030-03-05T08:00:00.000-00:00" ]))] r))) (take 500 (dc/index-range (dc/db conn) :invoice/client+date [17592186046356 #inst "2021-03-05T08:00:00.000-00:00" ] [17592186046356 #inst "2053-03-05T08:00:00.000-00:00" ] )) (def g (map vector (repeat #inst "2023-03-05T08:00:00.000-00:00") )) (def all-clients [17592186046356 17592186046363 17592186046366 17592186046371 17592186046373 17592186046378 17592186046380 17592186046385 17592186046394 17592186046397 17592186046400 17592186046404 17592186046409 17592186046415 17592186046422 17592186046428 17592186046437 17592186046447 17592186046456 17592186046465 17592186046472 17592186046478 17592186046491 17592186046499 17592186046513 17592186046520 17592186109023 17592193806897 17592195665346 17592196580407 17592203465691 17592204394806 17592219470393 17592219675333 17592221275294 17592232545948 17592232555238 17592232577980 17592232577988 17592232808650 17592232886729 17592232886786 17592232886793 17592232886797 17592232958090 17592233076577 17592233144301 17592233431334 17592233431814 17592234230520 17592234448526 17592234700485 17592234806481 17592234851859 17592235003983 17592235068155 17592235068158 17592235074859 17592235305451 17592235810873 17592235922068 17592236113837 17592236349303 17592236461666 17592236868866 17592236868871 17592238607837 17592238708423 17592238708558 17592241193003 17592242514773 17592242874891 17592243928280 17592244691542 17592244691558 17592244761680 17592245006804 17592245184339 17592246196802 17592247419073 17592247419185 17592247425545 17592249936256 17592249973733 17592250176578 17592250210564 17592250210567 17592250777772 17592250777854 17592253249909 17592257647588 17592258011361 17592258246710 17592258866422 17592260775415 17592262632255 17592264489873 17592264560519 17592265120447 17592271573602 17592271576404 17592273679867 17592275987623 17592275995130 17592275995135 17592276037255 17592277469850 17592278756108 17592280134939 17592281881509 17592284920305 17592285467793 17592286618015 17592288587524 17592289178758 17592289631589 17592290322936 17592291273963 17592291296031 17592291325248 17592291325326 17592291325452 17592291325766 17592291325864 17592291325954 17592291326043 17592291326115 17592291620408 17592292122045 17592294315344 17592295112116 17592296909432 17592296909449 17592296909452 17592297811962]) (do (println "INVOICES") (auto-ap.datomic/audit-transact-batch (->> (dc/q '[:find ?e ?c :in $ :where [?e :invoice/client ?c]] (dc/db conn) ) (map (fn [[i c]] {:db/id i :invoice/client c}))) {:user/name "hydrate-tuples"}) (println "TRANSACTIONS") (auto-ap.datomic/audit-transact-batch (->> (dc/q '[:find ?e ?c :in $ :where [?e :transaction/client ?c]] (dc/db conn) ) (map (fn [[i c]] {:db/id i :transaction/client c}))) {:user/name "hydrate-tuples"}) (println "JOURNALS") (auto-ap.datomic/audit-transact-batch (->> (dc/q '[:find ?e ?c :in $ :where [?e :journal-entry/client ?c]] (dc/db conn) ) (map (fn [[i c]] {:db/id i :journal-entry/client c}))) {:user/name "hydrate-tuples"}) (println "PAYMENTS") (auto-ap.datomic/audit-transact-batch (->> (dc/q '[:find ?e ?c :in $ :where [?e :payment/client ?c]] (dc/db conn) ) (map (fn [[i c]] {:db/id i :payment/client c}))) {:user/name "hydrate-tuples"}) (auto-ap.datomic/audit-transact-batch (->> (dc/q '[:find ?e ?c :in $ :where [?e :charge/client ?c]] (dc/db conn) ) (map (fn [[i c]] {:db/id i :charge/client c}))) {:user/name "hydrate-tuples"}) (auto-ap.datomic/audit-transact-batch (->> (dc/q '[:find ?e ?c :in $ :where [?e :cash-drawer-shift/client ?c]] (dc/db conn) ) (map (fn [[i c]] {:db/id i :cash-drawer-shift/client c}))) {:user/name "hydrate-tuples"}) (auto-ap.datomic/audit-transact-batch (->> (dc/q '[:find ?e ?c :in $ :where [?e :sales-refund/client ?c]] (dc/db conn) ) (map (fn [[i c]] {:db/id i :sales-refund/client c}))) {:user/name "hydrate-tuples"}) (auto-ap.datomic/audit-transact-batch (->> (dc/q '[:find ?e ?c :in $ :where [?e :expected-deposit/client ?c]] (dc/db conn) ) (map (fn [[i c]] {:db/id i :expected-deposit/client c}))) {:user/name "hydrate-tuples"}) )