On Wed, 16 Oct 2024 at 14:45, Marco van Tol <mvan...@ripe.net> wrote:

> Hi Mark,
>
> Thanks again for your answer.
>
> First of all, all of what I write below happened on a test list server, so
> no real harm was done.
> I'm just curious how to recover from this, and how to get to what I need.
> :-)
>
>
> On Wed, 11 Sept 2024 at 21:16, Mark Sapiro <m...@msapiro.net> wrote:
>
>> On 9/11/24 00:23, Marco van Tol wrote:
>> >
>> > We're interested in the development of a feature in mailman3 where we
>> can
>> > configure it to automatically expire/remove threads in/from the archive
>> > older than x number of days.
>>
>> The script at https://www.msapiro.net/scripts/prune_arch3 could be
>> easily modified to do this and then be run periodically by cron.
>>
>
> I made a modified version of the script, and ran it.
> (attachment: script-1.py)
>
> The script went on its way for a bit, and then blew up.
> (attachment: error-run-1.txt)
>

[...]

I made a change to the script that's really blunt but does work.

See the attached change.  I can make it more efficient by calling the
Email.objects.filter() once per loop instead of the current 2, but if you
have any other improvements they'd be welcome.


> And secondary: can I avoid the call to rebuild_index?  The actual
> production server has a massive count of messages.
>

This one very much stands, hopefully I can integrate the message deletion
mode-direct into the archive search index.

Thank you very much in advance!

Marco van Tol
RIPE NCC
import os
import sys
import django
from datetime import datetime, timezone

sys.path.insert(0, '/opt/mailman-web')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

django.setup()
from hyperkitty.models.email import Email

def usage():
    print(f'Usage: {sys.argv[0]} yyyy-mm-dd', file=sys.stderr)
    sys.exit(1)

if len(sys.argv) != 2:
    usage()
try:
    year, month, day = sys.argv[1].split('-')
except ValueError:
    usage()
try:
    cutoff = datetime(int(year), int(month), int(day), tzinfo=timezone.utc)
except (TypeError, ValueError):
    usage()

count = 0
while Email.objects.filter(mailinglist=4, date__lt=cutoff).count() > 0:
    msg = Email.objects.filter(mailinglist=4, date__lt=cutoff)[0]
    print(msg.mailinglist, msg.date, msg.sender)
    msg.delete()
    count += 1



print(f"Deleted {count} messages")
_______________________________________________
Mailman-Developers mailing list -- mailman-developers@python.org
To unsubscribe send an email to mailman-developers-le...@python.org
https://mail.python.org/mailman3/lists/mailman-developers.python.org/
Mailman FAQ: https://wiki.list.org/x/AgA3

Security Policy: https://wiki.list.org/x/QIA9

Reply via email to