| 233 | |
| 234 | @action(methods=["GET"], detail=True) |
| 235 | def count(self, request: request.Request, **kwargs) -> Response: |
| 236 | action = self.get_object() |
| 237 | # NOTE: never accepts cohort parameters so no need for explicit person_id_joined_alias |
| 238 | query, params = format_action_filter(team_id=action.team_id, action=action) |
| 239 | if query == "": |
| 240 | return Response({"count": 0}) |
| 241 | |
| 242 | results = sync_execute( |
| 243 | "SELECT count(1) FROM events WHERE team_id = %(team_id)s AND timestamp < %(before)s AND timestamp > %(after)s AND {}".format( |
| 244 | query |
| 245 | ), |
| 246 | { |
| 247 | "team_id": action.team_id, |
| 248 | "before": now().strftime("%Y-%m-%d %H:%M:%S.%f"), |
| 249 | "after": (now() - relativedelta(months=3)).strftime("%Y-%m-%d %H:%M:%S.%f"), |
| 250 | **params, |
| 251 | }, |
| 252 | ) |
| 253 | return Response({"count": results[0][0]}) |
| 254 | |
| 255 | |
| 256 | class LegacyActionViewSet(ActionViewSet): |