From 64e113835fdb7d00ecdc8f7f6c1ee222a91b338c Mon Sep 17 00:00:00 2001 From: daveoconnor Date: Mon, 12 Jan 2026 14:46:49 -0800 Subject: [PATCH] Correct slack activity miscount from fetch_slack_activity (#2056) --- docs/commands.md | 34 +++++++++++++ mailing_list/migrations/0006_listposting.py | 25 +++++++++ pycharm_debugger.py | 14 +++-- requirements-dev.in | 2 +- requirements-dev.txt | 2 +- .../commands/clear_slack_activity.py | 51 +++++++++++++++++++ .../commands/fetch_slack_activity.py | 15 +++++- 7 files changed, 134 insertions(+), 9 deletions(-) create mode 100644 mailing_list/migrations/0006_listposting.py create mode 100644 slack/management/commands/clear_slack_activity.py diff --git a/docs/commands.md b/docs/commands.md index 3c4023ef..687278dd 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -16,6 +16,7 @@ - [`update_library_version_dependencies`](#update_library_version_dependencies) - [`release_tasks`](#release_tasks) - [`refresh_users_github_photos`](#refresh_users_github_photos) + - [`clear_slack_activity`](#clear_slack_activity) ## `boost_setup` @@ -356,3 +357,36 @@ Preview which users would be updated: - Calls the `refresh_users_github_photos()` Celery task which queues photo updates for all users with GitHub usernames - With `--dry-run`, displays information about which users would be updated without making any changes + +## `clear_slack_activity` + +**Purpose**: Delete all slack activity tracking data from the database. This command removes all records from the `SlackActivityBucket` and `ChannelUpdateGap` tables, and resets the `last_update_ts` field to "0" for all channels. This is useful for resetting the slack activity tracking system to its initial state. + +**Example** + +```bash +./manage.py clear_slack_activity --confirm +``` + +**Options** + +| Options | Format | Description | +|--------------|--------|----------------------------------------------------------------------------------------------| +| `--confirm` | bool | Required flag to confirm deletion. The command will not execute without this flag. | + +**Usage Examples** + +Execute the deletion: +```bash +./manage.py clear_slack_activity --confirm +``` + +**Process** + +- Deletes all `SlackActivityBucket` records (message counts per user per channel per day) +- Deletes all `ChannelUpdateGap` records (tracking of message fetch progress) +- Resets `last_update_ts` to "0" for all `Channel` records +- All operations are performed within a database transaction to ensure atomicity +- Logs the number of records affected in each table + +**Warning**: This command permanently deletes all slack activity data. Use with caution. diff --git a/mailing_list/migrations/0006_listposting.py b/mailing_list/migrations/0006_listposting.py new file mode 100644 index 00000000..cae99373 --- /dev/null +++ b/mailing_list/migrations/0006_listposting.py @@ -0,0 +1,25 @@ +# Generated by Django 5.2.8 on 2026-01-06 01:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("mailing_list", "0005_postingdata_subscriptiondata"), + ] + + operations = [ + migrations.CreateModel( + name="ListPosting", + fields=[ + ("id", models.IntegerField(primary_key=True, serialize=False)), + ("date", models.DateTimeField()), + ("sender_id", models.CharField()), + ], + options={ + "db_table": "hyperkitty_email", + "managed": False, + }, + ), + ] diff --git a/pycharm_debugger.py b/pycharm_debugger.py index 2e023b5f..ebd219ba 100644 --- a/pycharm_debugger.py +++ b/pycharm_debugger.py @@ -1,8 +1,12 @@ def set_trace(): + import socket + import struct import pydevd_pycharm - # this ip address is for the gateway IP, equivalent to host.docker.internal which - # isn't available on all platforms - gateway_ip = "172.17.0.1" - # Use the same port number configured in PyCharm - pydevd_pycharm.settrace(host=gateway_ip, port=12345, suspend=False) + with open("/proc/net/route") as f: + for line in f.readlines()[1:]: + p = line.split() + if p and p[1] == "00000000": + gw = socket.inet_ntoa(struct.pack("