From 5df4033ac0cdf6daa0870d046a5a2b2e5dd17858 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 28 Mar 2023 09:40:45 -0700 Subject: [PATCH] Lots of fixes for cloud. --- src/clj/auto_ap/graphql.clj | 2 +- src/clj/auto_ap/graphql/accounts.clj | 4 ++-- src/clj/auto_ap/graphql/ezcater.clj | 12 +++++++++--- src/clj/auto_ap/graphql/transaction_rules.clj | 2 +- src/clj/auto_ap/routes/queries.clj | 11 ++++++----- things-to-search-for.txt | 8 +------- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 6f139b6c..987db0de 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -796,7 +796,7 @@ :account-for-vendor gq-accounts/default-for-vendor :get-user get-user :mutation/delete-transaction-rule gq-transaction-rules/delete-transaction-rule - :mutation/edit-user gq-users/edit-user + :mutation/edit-user gq-users/edit-user :mutation/upsert-transaction-rule gq-transaction-rules/upsert-transaction-rule :test-transaction-rule gq-transaction-rules/test-transaction-rule :run-transaction-rule gq-transaction-rules/run-transaction-rule diff --git a/src/clj/auto_ap/graphql/accounts.clj b/src/clj/auto_ap/graphql/accounts.clj index a420e50c..e8add62a 100644 --- a/src/clj/auto_ap/graphql/accounts.clj +++ b/src/clj/auto_ap/graphql/accounts.clj @@ -2,7 +2,6 @@ (:require [auto-ap.datomic :refer [audit-transact conn]] [auto-ap.datomic.accounts :as d-accounts] - [iol-ion.tx :refer [upsert-entity]] [auto-ap.graphql.utils :refer [->graphql <-graphql @@ -15,6 +14,7 @@ [auto-ap.search :as search] [auto-ap.utils :refer [heartbeat]] [datomic.client.api :as dc] + [iol-ion.tx :refer [random-tempid upsert-entity]] [mount.core :as mount] [yang.scheduler :as scheduler])) @@ -62,7 +62,7 @@ :account/code (str numeric-code) :account/client-overrides (mapv (fn [client-override] - {:db/id (:id client-override) + {:db/id (or (:id client-override) (random-tempid)) :account-client-override/client (:client-id client-override) :account-client-override/name (:name client-override) :account-client-override/search-terms (:name client-override)}) diff --git a/src/clj/auto_ap/graphql/ezcater.clj b/src/clj/auto_ap/graphql/ezcater.clj index 32f30171..30b4e77a 100644 --- a/src/clj/auto_ap/graphql/ezcater.clj +++ b/src/clj/auto_ap/graphql/ezcater.clj @@ -1,11 +1,13 @@ (ns auto-ap.graphql.ezcater (:require [auto-ap.datomic :refer [conn]] - [auto-ap.graphql.utils :refer [assert-admin cleanse-query]] + [auto-ap.graphql.utils + :refer [assert-admin attach-tracing-resolvers cleanse-query]] [auto-ap.search :as search] - [com.walmartlabs.lacinia.util :refer [attach-resolvers]] + [auto-ap.utils :refer [heartbeat]] [datomic.client.api :as dc] - [auto-ap.graphql.utils :refer [attach-tracing-resolvers]])) + [mount.core :as mount] + [yang.scheduler :as scheduler])) (defn search [context args _] (assert-admin (:id context)) @@ -26,6 +28,10 @@ :text (:ezcater-caterer/search-terms result)}) "ezcater-caterer")) +(mount/defstate indexer + :start (scheduler/every (* 5 60 1000) (heartbeat rebuild-search-index "rebuild-search-index")) + :stop (scheduler/stop indexer)) + (def objects {:ezcater_caterer {:fields {:name {:type 'String} :id {:type :id}}}}) diff --git a/src/clj/auto_ap/graphql/transaction_rules.clj b/src/clj/auto_ap/graphql/transaction_rules.clj index 714225db..ed7d75e1 100644 --- a/src/clj/auto_ap/graphql/transaction_rules.clj +++ b/src/clj/auto_ap/graphql/transaction_rules.clj @@ -77,7 +77,7 @@ rule-id (if id id "transaction-rule") - transaction [`(upsert-entity ~#:transaction-rule {:db/id rule-id + transaction [`(upsert-entity ~#:transaction-rule {:db/id (or rule-id (random-tempid)) :description description :note note :client client_id diff --git a/src/clj/auto_ap/routes/queries.clj b/src/clj/auto_ap/routes/queries.clj index 4dc2db76..ee33517e 100644 --- a/src/clj/auto_ap/routes/queries.clj +++ b/src/clj/auto_ap/routes/queries.clj @@ -1,8 +1,7 @@ (ns auto-ap.routes.queries (:require [amazonica.aws.s3 :as s3] - [auto-ap.datomic :refer [conn pull-attr]] - [iol-ion.tx :refer [upsert-entity]] + [auto-ap.datomic :refer [conn pull-attr pull-id]] [auto-ap.graphql.utils :refer [assert-admin]] [clojure.data.csv :as csv] [clojure.edn :as edn] @@ -12,7 +11,7 @@ [com.unbounce.dogstatsd.core :as statsd] [config.core :refer [env]] [datomic.client.api :as dc] - + [iol-ion.tx :refer [random-tempid upsert-entity]] [ring.middleware.json :refer [wrap-json-response]] [ring.util.request :refer [body-string]] [unilog.context :as lc]) @@ -41,11 +40,13 @@ (defn put-query [guid body note & [lookup-key client]] - (let [guid (if lookup-key + (let [id (pull-id (dc/db conn) [:saved-query/lookup-key lookup-key]) + guid (if lookup-key (or (pull-attr (dc/db conn) :saved-query/guid [:saved-query/lookup-key lookup-key]) guid) guid)] - (dc/transact conn [`(upsert-entity ~{:saved-query/guid guid + (dc/transact conn [`(upsert-entity ~{:db/id (or id (random-tempid)) + :saved-query/guid guid :saved-query/description note :saved-query/key (str "queries/" guid) :saved-query/client client diff --git a/things-to-search-for.txt b/things-to-search-for.txt index a90231ff..0a3cb56e 100644 --- a/things-to-search-for.txt +++ b/things-to-search-for.txt @@ -1,12 +1,5 @@ -or-join syntax changed? -(probably fixed) regex no longer supported as argument for query. Check vendor datomic for how to do it right. it looks like there are a bbunch of orrphaned customizations for accounts, breaking indexes -ezcater graphql needs search index too -make sure that temporary ids are set on all new things when using upsert-entity -Wrap tests around every api call -upsertentity Look at how address works on client save. There's agood chance that we should make saving a rel with only a temp id just resolve it to null upsertledger - matching transaction rule might not assign an account. Other things might not assign accounts. This is an assertion that is commented out. Determine consequence of disabling -Search for all usages of :reset or :pay or dollars= Fix searching * indexing should happen more regularly, and just look for changes since last time it was run @@ -39,3 +32,4 @@ Future improvements: Make reports just be based on running-balances get rid of account-groups move to solr +upsertentity Look at how address works on client save. There's agood chance that we should make saving a rel with only a temp id just resolve it to null