Skip to content
Snippets Groups Projects
Commit 811086b5 authored by Cam Saül's avatar Cam Saül Committed by GitHub
Browse files

Merge pull request #5406 from metabase/dont-send-archived-cards-in-pulses

Don't send/show archived cards in pulses (#5224)
parents 462cfa3c 2c88569a
Branches
Tags
No related merge requests found
......@@ -77,6 +77,7 @@
"Return the `Cards` associated with this PULSE."
[{:keys [id]}]
(db/select [Card :id :name :description :display]
:archived false
(mdb/join [Card :id] [PulseCard :card_id])
(db/qualify PulseCard :pulse_id) id
{:order-by [[(db/qualify PulseCard :position) :asc]]}))
......@@ -119,7 +120,7 @@
(db/delete! PulseCard :pulse_id id)
;; now just insert all of the cards that were given to us
(when (seq card-ids)
(let [cards (map-indexed (fn [idx itm] {:pulse_id id :card_id itm :position idx}) card-ids)]
(let [cards (map-indexed (fn [i card-id] {:pulse_id id, :card_id card-id, :position i}) card-ids)]
(db/insert-many! PulseCard cards))))
......@@ -207,7 +208,7 @@
(db/transaction
;; update the pulse itself
(db/update! Pulse id, :name name, :skip_if_empty skip-if-empty?)
;; update cards (only if they changed)
;; update cards (only if they changed). Order for the cards is important which is why we're not using select-field
(when (not= cards (map :card_id (db/select [PulseCard :card_id], :pulse_id id, {:order-by [[:position :asc]]})))
(update-pulse-cards! pulse cards))
;; update channels
......
......@@ -19,7 +19,7 @@
"Execute the query for a single card with CARD-ID. OPTIONS are passed along to `dataset-query`."
[card-id & {:as options}]
{:pre [(integer? card-id)]}
(when-let [card (Card card-id)]
(when-let [card (Card :id card-id, :archived false)]
(let [{:keys [creator_id dataset_query]} card]
(try
{:card card
......@@ -86,8 +86,10 @@
(send-pulse! pulse :channel-ids [312]) Send only to Channel with :id = 312"
[{:keys [cards], :as pulse} & {:keys [channel-ids]}]
{:pre [(map? pulse) (every? map? cards) (every? :id cards)]}
(let [results (for [card cards]
(execute-card (:id card), :pulse-id (:id pulse))) ; Pulse ID may be `nil` if the Pulse isn't saved yet
(let [results (for [card cards
:let [result (execute-card (:id card), :pulse-id (:id pulse))] ; Pulse ID may be `nil` if the Pulse isn't saved yet
:when result] ; some cards may return empty results, e.g. if the card has been archived
result)
channel-ids (or channel-ids (mapv :id (:channels pulse)))]
(when-not (and (:skip_if_empty pulse) (are-all-cards-empty? results))
(doseq [channel-id channel-ids]
......
......@@ -58,10 +58,10 @@
([]
(set-backend! (config/config-kw :mb-qp-cache-backend)))
([backend]
(let [backend-ns (symbol (str "metabase.query-processor.middleware.cache-backend." (munge (name backend))))]
(require backend-ns)
(let [backend-ns-symb (symbol (str "metabase.query-processor.middleware.cache-backend." (munge (name backend))))]
(require backend-ns-symb)
(log/info "Using query processor cache backend:" (u/format-color 'blue backend) (u/emoji "💾"))
(reset! backend-instance (get-backend-instance-in-namespace backend-ns)))))
(reset! backend-instance (get-backend-instance-in-namespace backend-ns-symb)))))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment