clientize.

This commit is contained in:
2023-05-05 11:28:08 -07:00
parent eacd6b4537
commit 5d0bf6a8d8
6 changed files with 56 additions and 37 deletions

View File

@@ -1,6 +1,7 @@
{:db {:server "localhost"} {:db {:server "localhost"}
:scheme "http" :scheme "http"
:solr-uri "http://localhost:8983" :solr-uri "http://localhost:8983"
:solr-impl :solr
:client-config {:server-type :dev-local :client-config {:server-type :dev-local
:system "dev"} :system "dev"}
:db-name "prod-migration2" :db-name "prod-migration2"

View File

@@ -1,6 +1,7 @@
{:scheme "https" {:scheme "https"
:db-name "prod-mirror2" :db-name "prod-mirror2"
:solr-uri "http://solr-prod-cloud.local:8983" :solr-uri "http://solr-prod-cloud.local:8983"
:solr-impl :solr
:datomic-url "datomic:ddb://us-east-1/iol-dev/dev" :datomic-url "datomic:ddb://us-east-1/iol-dev/dev"
:dd-env "prod-cloud" :dd-env "prod-cloud"
:dd-service "integreat-app-cloud" :dd-service "integreat-app-cloud"

View File

@@ -1,6 +1,7 @@
{:db {:server "database"} {:db {:server "database"}
:datomic-url "datomic:ddb://us-east-1/integreat/integreat-prod" :datomic-url "datomic:ddb://us-east-1/integreat/integreat-prod"
:solr-uri "http://solr-prod.local:8983" :solr-uri "http://solr-prod.local:8983"
:solr-impl :solr
:scheme "https" :scheme "https"
:dd-env "prod" :dd-env "prod"
:dd-service "integreat-app" :dd-service "integreat-app"

View File

@@ -117,43 +117,61 @@
"type" "payment"})) "type" "payment"}))
(defprotocol SolrClient
(index-documents [this xs])
(query [this q])
(delete [this]))
(defn index-documents [xs] (defrecord RealSolrClient [solr-uri]
(client/post
(str solr-uri "/solr/invoices/update?commitWithin=15000")
{:headers {"Content-Type" "application/json"}
:socket-timeout 30000
:connection-timeout 30000
:method "POST"
:body (json/write-str (filter identity (map datomic->solr xs)))}))
(defn query [q] SolrClient
(-> (client/post (str solr-uri "/solr/invoices/query") (index-documents [this xs]
{:body (json/write-str {"query" q (client/post
"fields" "id, date, amount, type, description, number, client_code, client_id, vendor_name"}) (str solr-uri "/solr/invoices/update?commitWithin=15000")
:socket-timeout 30000 {:headers {"Content-Type" "application/json"}
:connection-timeout 30000 :socket-timeout 30000
:headers {"Content-Type" "application/json"} :connection-timeout 30000
:as :json} :method "POST"
) :body (json/write-str (filter identity (map datomic->solr xs)))}))
:body
:response
:docs))
(defn solr-delete [] (query [this q]
(client/post (-> (client/post (str solr-uri "/solr/invoices/query")
(str solr-uri "/solr/invoices/update?commitWithin=1000") {:body (json/write-str {"query" q
{:headers {"Content-Type" "application/json"} "fields" "id, date, amount, type, description, number, client_code, client_id, vendor_name"})
:method "POST" :socket-timeout 30000
:body (json/write-str {"delete" {"query" "*:*"}})}) :connection-timeout 30000
) :headers {"Content-Type" "application/json"}
:as :json}
)
:body
:response
:docs))
(delete [this]
(client/post
(str solr-uri "/solr/invoices/update?commitWithin=1000")
{:headers {"Content-Type" "application/json"}
:method "POST"
:body (json/write-str {"delete" {"query" "*:*"}})})))
(defrecord MockSolrClient []
SolrClient
(index-documents [this xs]
nil)
(query [this q]
nil)
(delete [this]
nil))
(def impl (if (= :solr (:solr-impl env))
(->RealSolrClient (:solr-uri env))
(->MockSolrClient )))
(defn touch-with-ledger [i] (defn touch-with-ledger [i]
(index-documents [i (index-documents impl [i
(pull-id (dc/db conn) [:journal-entry/original-entity i])])) (pull-id (dc/db conn) [:journal-entry/original-entity i])]))
(defn touch [i] (defn touch [i]
(index-documents [i])) (index-documents impl [i]))

View File

@@ -1,12 +1,10 @@
(ns auto-ap.ssr.search (ns auto-ap.ssr.search
(:require (:require
[auto-ap.graphql.utils :refer [can-see-client?]] [auto-ap.graphql.utils :refer [can-see-client?]]
[auto-ap.solr :as solr]
[auto-ap.ssr.utils :refer [html-response]] [auto-ap.ssr.utils :refer [html-response]]
[auto-ap.time :as atime] [auto-ap.time :as atime]
[clj-http.client :as client]
[clojure.data.json :as json]
[clojure.string :as str] [clojure.string :as str]
[auto-ap.solr :as solr]
[com.brunobonacci.mulog :as mu])) [com.brunobonacci.mulog :as mu]))
(defn try-cleanse-date [d] (defn try-cleanse-date [d]
@@ -55,7 +53,7 @@
(into [] (into []
(filter (fn [d] (filter (fn [d]
(can-see-client? id (first (:client_id d))))) (can-see-client? id (first (:client_id d)))))
(solr/query (q->solr-q q)))) (solr/query solr/impl (q->solr-q q))))
(defn search-results* [q id] (defn search-results* [q id]

View File

@@ -573,7 +573,7 @@
(partition-all 1000))] (partition-all 1000))]
(print ".") (print ".")
(flush) (flush)
(solr/index-documents batch)) (solr/index-documents solr/impl batch))
(doseq [batch (->> (dc/qseq {:query '[:find ?i (doseq [batch (->> (dc/qseq {:query '[:find ?i
:in $ :in $
@@ -584,7 +584,7 @@
(partition-all 1000))] (partition-all 1000))]
(print ".") (print ".")
(flush) (flush)
(solr/index-documents batch)) (solr/index-documents solr/impl batch))
(doseq [batch (->> (dc/qseq {:query '[:find ?i (doseq [batch (->> (dc/qseq {:query '[:find ?i
:in $ :in $
@@ -595,7 +595,7 @@
(partition-all 1000))] (partition-all 1000))]
(print ".") (print ".")
(flush) (flush)
(solr/index-documents batch)) (solr/index-documents solr/impl batch))
(doseq [batch (->> (dc/qseq {:query '[:find ?i (doseq [batch (->> (dc/qseq {:query '[:find ?i
:in $ :in $
:where [?i :journal-entry/date]] :where [?i :journal-entry/date]]
@@ -604,7 +604,7 @@
(partition-all 1000))] (partition-all 1000))]
(print ".") (print ".")
(flush) (flush)
(solr/index-documents batch))) (solr/index-documents solr/impl batch)))
(defn setup-sales-orders [] (defn setup-sales-orders []
(doseq [n (->> (dc/qseq {:query '[:find ?s ?c :where [?s :sales-order/client ?c]] :args [(dc/db auto-ap.datomic/conn)]}) (doseq [n (->> (dc/qseq {:query '[:find ?s ?c :where [?s :sales-order/client ?c]] :args [(dc/db auto-ap.datomic/conn)]})