Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add view_count for cards and dashboards and populate it from view_log #41840

Merged
merged 4 commits into from
Apr 26, 2024

Conversation

calherries
Copy link
Contributor

@calherries calherries commented Apr 25, 2024

Epic: #38229
Technical doc

This is the first PR of two for Milestone 4 in the epic. It adds a new column view_count to report_card and report_dashboard. The columns are not included in revision history objects, but they are serialized in serialization.

A PR following this one will modify :event/card-read and :event/dashboard-read event handlers to increment the column when a user views the card or dashboard.

The use case for Milestone 4 is TBD, but most likely this would be shown in collections to help users find relevant content or help rank search results.

@metabase-bot metabase-bot bot added the .Team/BackendComponents also known as BEC label Apr 25, 2024
@calherries calherries added the no-backport Do not backport this PR to any branch label Apr 25, 2024
@calherries calherries changed the title Migrations to add and populate view_count for cards and dashboards Add view_count for cards and dashboards and populate it from view_log Apr 25, 2024
Copy link

replay-io bot commented Apr 25, 2024

Status Complete ↗︎
Commit b7b94ed
Results
⚠️ 10 Flaky
2422 Passed

@calherries calherries requested review from a team and removed request for a team April 26, 2024 07:29
- changeSet:
id: v50.2024-04-25T16:29:34
author: calherries
comment: Populate report_dashboard.view_count
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps worth explaining the data gap for OSS installations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's actually no data gap. We haven't stopped populating the view_log yet. That's only planned for v50

Comment on lines +6660 to +6661
SET view_count = (
SELECT count(*)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just sanity checking - the only differences between these two queries are whether view_count is qualified and whether count(*) is capitalized. Are both of these really required divergences? Just want to shake the notion that perhaps the split comes from an earlier revision with a more complex query.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count being capitalized doesn't matter, view_count being qualified is the key difference. It's required for MySQL but postgres and h2 don't like it.

(deftest view-count-test
(testing "report_card.view_count and report_dashboard.view_count should be populated"
(impl/test-migrations ["v50.2024-04-25T16:29:31" "v50.2024-04-25T16:29:34"] [migrate!]
(let [user-id 13371338 ; use internal user to avoid creating a real user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We hard code this in a few places. My "clean coder" cosmetic indoctrination is burning. What's the reason not to use metabase.config/internal-mb-user-id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's unlikely, but it could change. this is a migration test, so should never change

@calherries calherries enabled auto-merge (squash) April 26, 2024 11:11
@calherries calherries merged commit 3a80be3 into master Apr 26, 2024
112 checks passed
@calherries calherries deleted the view-count-columns branch April 26, 2024 12:07
Copy link

@calherries Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport Do not backport this PR to any branch .Team/BackendComponents also known as BEC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants