villebro commented on a change in pull request #11481:
URL:
https://github.com/apache/incubator-superset/pull/11481#discussion_r514937147
##########
File path: superset/views/core.py
##########
@@ -1198,37 +1200,91 @@ def recent_activity( # pylint: disable=no-self-use
limit = int(request.args["limit"])
else:
limit = 1000
+ actions = request.args.get("actions", "explore,dashboard").split(",")
+ # whether to get distinct subjects
+ distinct = request.args.get("distinct") != "false"
- qry = (
- db.session.query(Log, Dashboard, Slice)
- .outerjoin(Dashboard, Dashboard.id == Log.dashboard_id)
- .outerjoin(Slice, Slice.id == Log.slice_id)
- .filter(
- and_(
- Log.action.in_(("queries", "shortner", "sql_json")),
- Log.user_id == user_id,
+ has_subject_title = or_(
+ and_(
+ Dashboard.dashboard_title is not None,
Dashboard.dashboard_title != "",
+ ),
+ and_(Slice.slice_name is not None, Slice.slice_name != ""),
+ )
+
+ if distinct:
+ one_year_ago = datetime.today() - timedelta(days=365)
+ subqry = (
+ db.session.query(
+ Log.dashboard_id,
+ Log.slice_id,
+ Log.action,
+ func.max(Log.dttm).label("dttm"),
)
+ .group_by(Log.dashboard_id, Log.slice_id, Log.action)
+ .filter(
+ and_(
+ Log.action.in_(actions),
+ Log.user_id == user_id,
+ # limit to one year of data to improve performance
+ Log.dttm > one_year_ago,
+ or_(Log.dashboard_id is not None, Log.slice_id is not
None),
Review comment:
Yeah, it's a shame the linter can't (to my knowledge) be set to ignore
those checks on sqla orm ops.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]