Skip to content

Commit

Permalink
Increment counts on view
Browse files Browse the repository at this point in the history
  • Loading branch information
calherries committed Apr 26, 2024
1 parent 53f77f2 commit 61089ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/metabase/events/view_log.clj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
:topic topic
:user-id user-id}
(try
(increment-view-counts! :model/Table (:id object))
(let [table-id (u/id object)
database-id (:db_id object)
has-access? (when (= api/*current-user-id* user-id)
Expand Down
13 changes: 13 additions & 0 deletions test/metabase/events/view_log_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@
(is (= 2 (t2/select-one-fn :view_count :model/Card (:id card)))
"view_count for cards on the dashboard be incremented too")))))

(deftest table-read-view-count-test
(mt/with-temp [:model/User user {}
:model/Table table {}]
(testing "A card read events are recorded by a card's view_count"
(is (= 0 (:view_count table))
"view_count should be 0 before the event is published")
(events/publish-event! :event/table-read {:object table :user-id (u/the-id user)})
(is (= 1 (t2/select-one-fn :view_count :model/Table (:id table)))
"view_count should be incremented")
(events/publish-event! :event/table-read {:object table :user-id (u/the-id user)})
(is (= 2 (t2/select-one-fn :view_count :model/Table (:id table)))
"view_count should be incremented"))))


;;; ---------------------------------------- API tests begin -----------------------------------------

Expand Down

0 comments on commit 61089ae

Please sign in to comment.