MCPcopy
hub / github.com/PostHog/posthog / run

Method run

posthog/queries/trends/trends.py:207–230  ·  view source on GitHub ↗
(self, filter: Filter, team: Team, *args, **kwargs)

Source from the content-addressed store, hash-verified

205 return flat_results
206
207 def run(self, filter: Filter, team: Team, *args, **kwargs) -> List[Dict[str, Any]]:
208 actions = Action.objects.filter(team_id=team.pk).order_by("-id")
209 if len(filter.actions) > 0:
210 actions = Action.objects.filter(pk__in=[entity.id for entity in filter.actions], team_id=team.pk)
211 actions = actions.prefetch_related(Prefetch("steps", queryset=ActionStep.objects.order_by("id")))
212
213 if filter.formula:
214 return handle_compare(filter, self._run_formula_query, team)
215
216 for entity in filter.entities:
217 if entity.type == TREND_FILTER_TYPE_ACTIONS:
218 try:
219 entity.name = actions.get(id=entity.id).name
220 except Action.DoesNotExist:
221 return []
222
223 if len(filter.entities) == 1 or filter.compare:
224 result = []
225 for entity in filter.entities:
226 result.extend(handle_compare(filter, self._run_query, team, entity=entity))
227 else:
228 result = self._run_parallel(filter, team)
229
230 return result
231
232 def _format_serialized(self, entity: Entity, result: List[Dict[str, Any]]):
233 serialized_data = []

Calls 4

_run_parallelMethod · 0.95
handle_compareFunction · 0.90
filterMethod · 0.80
getMethod · 0.65