-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
New Recents API Format #42239
New Recents API Format #42239
Conversation
Some comments: A nice ns docstring:(ns metabase.models.recent-views
"The Recent Views table is used to track the most recent views of objects such as Cards, Models, Tables, Dashboards,
and Collections for each user. It offers a simple api to add a recent, and fetch the list of recents.
Fetch recent items: `(recent-view/get-list <user-id>)`
add recent item: `(recent-views/update-users-recent-views! <user-id> <model> <model-id>)`
When adding a recent item, duplicates will be removed, and [[*recent-views-stored-per-user-per-model*]] (20
currently) are kept of each entity type. Ie, if you were to view lots of cards, it would not push collections and
dashboards out of your recents."
,,,) (note, enumerating the API makes distinct idsI see you're doing most of this in SQL. Want to throw out perhaps an easier impl. recent-views=> (->> (set/index (t2/select :model/RecentViews
:user_id 1
{:order-by [[:timestamp :desc]]})
[:model :model_id])
(mapcat (comp next val))
(map :id))
(40
61
48
49
,,,) I think mine is easier to read. And since we always load this all in memory, felt appropriate. Up to you to accept or decline the change. Issue in spec@@ -212,7 +228,7 @@
:model :table
:can_write (mi/can-write? :model/Table model_id)
:timestamp (str timestamp)
- :database {:id (:database-id table)
+ :database {:id (:db_id table)
:name (:name table)}}))
|
I'm getting this error:
|
|
- also include some debug logging
also gets tests passing locally
no more nils passed through the app
* fix tests * new API payload format for recents and populars * update url generation * update recents components * update tests * only show 5 recents in command palette * remove unused types * update tests * obey the linter * type updates * fix unit test * change where we filter recents --------- Co-authored-by: Bryan Maass <[email protected]>
f878b56
to
545a5c6
Compare
(map #(-> % | ||
(assoc :timestamp (:max_ts % "")) | ||
recent-views/fill-recent-view-info))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - might be a bit more readable to break this out into two separate maps, instead of nested threading macros? and/or to use a transducer for the whole pipeline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I landed here because I found the transducer style to be harder to read, though it does have the memory pressure benefit. But then in the other direction: for doing 2 maps we'd be creating another intermediate sequence.
(nil? (:archived model)) | ||
(throw (ex-info "Archived field is nil" {:model model})))) | ||
|
||
(defmethod fill-recent-view-info :card [{:keys [_model model_id timestamp model_object]}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense for the impls of this multimethod to live in the model namespaces for each model? That way each model is responsible for what information is included in recent views, rather than blowing up this namespace with all the implementations. That's the pattern I followed with audit-log/model-details
for instance.
Don't need to block on this, just a suggestion but it could go either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad you asked! I thought about that too, but I figured that I wanted these methods to be seen from the POV of a recent view item, instead of a model. Part of the reason for that is the impedence mismatch between :model/Card being both questions and models (and metrics etc if we ever add those?). So I thought it was more simple to handle things as they are on the api side, instead of the way they are on our model/instance side.
@escherize Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone? |
resolves #41957
The way this works is by querying
recent_views
for the last 20 of each sort of model. This query joins with report_card so we can differentiate questions (cards) from datasets (models).Then each one is passed through post-process, a multimethod that dispatches on the model (with a distinction between cards and datasets) which does some classification, and adds details to each RecentViews/Item.
Tasks
recent_views
properlymoderated_status
on cards, models, (and maybe dashboards)