From 99b6d822f6001ca236d09a3dda9b7928b67443c9 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 8 Dec 2020 20:43:27 -0800 Subject: [PATCH] performance optimization, much faster when only looking up check if transaction not found. --- src/clj/auto_ap/yodlee/import.clj | 63 ++++++++++++++++--------------- terraform/deploy.tf | 4 +- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/clj/auto_ap/yodlee/import.clj b/src/clj/auto_ap/yodlee/import.clj index 67e789b4..c29f8526 100644 --- a/src/clj/auto_ap/yodlee/import.clj +++ b/src/clj/auto_ap/yodlee/import.clj @@ -92,7 +92,7 @@ client (:client/_bank-accounts bank-account) client-id (:db/id client) valid-locations (or (:bank-account/locations bank-account) (:client/locations client)) - check (transaction->payment transaction check-number client-id bank-account-id amount id) + date (time/parse date "YYYY-MM-dd")] :when (and client-id (not (existing (sha-256 (str id)))) @@ -101,38 +101,39 @@ (or (not (:start-date bank-account)) (t/after? date (:start-date bank-account))) )] - (-> - #:transaction - {:post-date (coerce/to-date (time/parse post-date "YYYY-MM-dd")) - :id (sha-256 (str id)) - :account-id account-id - :date (coerce/to-date date) - :amount (double amount) - :description-original (some-> description-original (str/replace #"\s+" " ")) - :description-simple (some-> description-simple (str/replace #"\s+" " ")) - :approval-status (if check - :transaction-approval-status/approved - :transaction-approval-status/unapproved) - :type type - :status status - :client client-id - :check-number check-number - :bank-account bank-account-id - :payment (when check - {:db/id (:db/id check) - :payment/status :payment-status/cleared}) + (let [check (transaction->payment transaction check-number client-id bank-account-id amount id)] + (-> + #:transaction + {:post-date (coerce/to-date (time/parse post-date "YYYY-MM-dd")) + :id (sha-256 (str id)) + :account-id account-id + :date (coerce/to-date date) + :amount (double amount) + :description-original (some-> description-original (str/replace #"\s+" " ")) + :description-simple (some-> description-simple (str/replace #"\s+" " ")) + :approval-status (if check + :transaction-approval-status/approved + :transaction-approval-status/unapproved) + :type type + :status status + :client client-id + :check-number check-number + :bank-account bank-account-id + :payment (when check + {:db/id (:db/id check) + :payment/status :payment-status/cleared}) - :vendor (when check - (:db/id (:payment/vendor check))) - :location (when check - "A") - :accounts (when check - [#:transaction-account {:account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"])) - :location "A" - :amount (Math/abs (double amount))}])} + :vendor (when check + (:db/id (:payment/vendor check))) + :location (when check + "A") + :accounts (when check + [#:transaction-account {:account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"])) + :location "A" + :amount (Math/abs (double amount))}])} - (apply-rules valid-locations) - remove-nils)))) + (apply-rules valid-locations) + remove-nils))))) (defn batch-transact [transactions] diff --git a/terraform/deploy.tf b/terraform/deploy.tf index a3e8bd43..9ae3abde 100644 --- a/terraform/deploy.tf +++ b/terraform/deploy.tf @@ -83,8 +83,8 @@ resource "aws_lb_target_group" "integreat_app" { path = "/api/health-check" port = "traffic-port" protocol = "HTTP" - timeout = 5 - unhealthy_threshold = 2 + timeout = 14 + unhealthy_threshold = 5 } stickiness {