villebro commented on a change in pull request #11481:
URL: 
https://github.com/apache/incubator-superset/pull/11481#discussion_r514906007



##########
File path: superset/views/core.py
##########
@@ -35,7 +35,9 @@
 from sqlalchemy import and_, or_
 from sqlalchemy.engine.url import make_url
 from sqlalchemy.exc import ArgumentError, DBAPIError, NoSuchModuleError, 
SQLAlchemyError
+from sqlalchemy.orm import Load, load_only

Review comment:
       These don't appear to be used anywhere

##########
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:
       `is not None` will be evaluated prior to compilation, should be replaced 
by
   ```suggestion
                           or_(Log.dashboard_id != None, Log.slice_id != None),
   ```




----------------------------------------------------------------
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]

Reply via email to