-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdp): turn off all remaining legacy action webhooks (#27735)
- Loading branch information
1 parent
73ad37d
commit 06eb413
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Generated by Django 4.2.18 on 2025-01-21 16:25 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def disable_all_action_webhooks(apps, schema_editor): | ||
Action = apps.get_model("posthog", "Action") | ||
Team = apps.get_model("posthog", "Team") | ||
|
||
# Get teams that have Slack webhooks configured | ||
teams_with_slack = ( | ||
Team.objects.exclude(slack_incoming_webhook__isnull=True) | ||
.exclude(slack_incoming_webhook="") | ||
.values_list("id", flat=True) | ||
) | ||
|
||
# Get the query without evaluating it | ||
query = Action.objects.filter(post_to_slack=True, deleted=False, team_id__in=teams_with_slack).order_by("id") | ||
|
||
batch_size = 100 | ||
actions_to_update = [] | ||
processed_count = 0 | ||
|
||
# Use iterator() to fetch records in batches | ||
for action in query.iterator(chunk_size=batch_size): | ||
action.post_to_slack = False | ||
actions_to_update.append(action) | ||
processed_count += 1 | ||
|
||
# Bulk update when we reach batch_size | ||
if len(actions_to_update) >= batch_size: | ||
Action.objects.bulk_update(actions_to_update, ["post_to_slack"]) | ||
print(f"Processed {processed_count} actions") # noqa: T201 | ||
actions_to_update = [] | ||
|
||
# Handle any remaining items | ||
if actions_to_update: | ||
Action.objects.bulk_update(actions_to_update, ["post_to_slack"]) | ||
print(f"Processed {processed_count} actions") # noqa: T201 | ||
|
||
print(f"Processed {processed_count} actions in total") # noqa: T201 | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("posthog", "0551_batchimport"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
disable_all_action_webhooks, | ||
reverse_code=migrations.RunPython.noop, | ||
elidable=True, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0551_batchimport | ||
0552_turn_off_all_action_webhooks |