Compare commits

...

3 Commits

Author SHA1 Message Date
Nathan Voxland
2881136730 Only update search index if instance was actually updated 2025-05-01 10:05:57 -05:00
Nathan Voxland
10cfe891bb Only update search index if instance was actually updated 2025-04-30 16:58:01 -05:00
Nathan Voxland
8c80c8107f Only update search index if instance was actually updated 2025-04-30 16:39:07 -05:00
2 changed files with 5 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
(ns metabase.search.models
(:require
[metabase.search.core :as search]
[metabase.util :as u]
[toucan2.core :as t2]))
;; Models must derive from :hook/search-index if their state can influence the contents of the Search Index.
@@ -15,7 +16,7 @@
(t2/define-after-update :hook/search-index
[instance]
(search/update! instance)
(when (and (t2/instance? instance) (t2/changes instance)) (search/update! instance))
nil)
;; Too much of a performance risk.

View File

@@ -343,13 +343,14 @@
instance)))
(defn search-models-to-update
"Given an updated or created instance, return a description of which search-models to (re)index."
"Given an updated or created instance, return a description of which search-models to (re)index.
Set `always?` to true if the instance is newly inserted OR you want to force the update"
[instance & [always?]]
(let [raw-values (delay (instance->db-values instance))]
(into #{}
(keep
(fn [{:keys [search-model fields where]}]
(when (or always? (and fields (some fields (keys (or (t2/changes instance) instance)))))
(when (or always? (and fields (some fields (keys (t2/changes instance)))))
[search-model (insert-values where :updated @raw-values)])))
(get (model-hooks) (t2/model instance)))))