From f8690edbb85d5c8b024e3ad7b1ba48a447f2894f Mon Sep 17 00:00:00 2001 From: Bryce Date: Tue, 31 Oct 2023 12:52:52 -0700 Subject: [PATCH] Makes refresh much faster --- src/clj/auto_ap/ledger.clj | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/clj/auto_ap/ledger.clj b/src/clj/auto_ap/ledger.clj index 363bcdbf..fc23bafd 100644 --- a/src/clj/auto_ap/ledger.clj +++ b/src/clj/auto_ap/ledger.clj @@ -528,16 +528,25 @@ :client-index i :client-count (count clients))))))) +(defn clients-needing-refresh [] + (map first + (dc/q '[:find (pull ?c [:client/code :db/id]) + :in $ $recent + :where [$recent ?jel :journal-entry-line/dirty true] + [$ ?je :journal-entry/line-items ?jel] + [$ ?je :journal-entry/client ?c]] + (dc/db conn) + (dc/since + (dc/db conn) + (c/to-date (t/plus (t/now) (t/hours -4))))))) + (defn refresh-running-balance-cache - ([] (refresh-running-balance-cache (shuffle (map first - (dc/q '[:find (pull ?c [:client/code :db/id]) - :where [?c :client/code]] - (dc/db conn)))))) + ([] (refresh-running-balance-cache (shuffle (clients-needing-refresh)))) ([clients] (doseq [[c i] (map vector clients (range))] (mu/trace ::building-running-balance [:client c] - (mu/with-context {:client c + (mu/with-context {:client c :client-index i :client-count (count clients)} (mu/log ::searching-for-accounts)