<commit_before>import datetime

from django.core.management.base import BaseCommand, CommandError

from clowder_account.models import Company
from clowder_server.emailer import send_alert
from clowder_server.models import Alert, Ping

class Command(BaseCommand):
    help = 'Checks and sends alerts'

    def handle(self, *args, **options):

        # delete old pings
        for company in Company.objects.all():
            pings_by_name = Ping.objects.filter(company=company).distinct('name')

            if not pings_by_name:
                continue

            max_per_ping = 500 / len(pings_by_name)

            for name in pings_by_name:
                pings = Ping.objects.filter(company=company, name=name).order_by('-create')[:max_per_ping]
                pings = list(pings.values_list("id", flat=True))
                Ping.objects.filter(company=company, name=name).exclude(pk__in=pings).delete()

        # send alerts
        alerts = Alert.objects.filter(notify_at__lte=datetime.datetime.now)
        for alert in alerts:
            send_alert(alert.company, alert.name)
            alert.notify_at = None
            alert.save()<commit_msg>Store more pings per transaction<commit_after>import datetime

from django.core.management.base import BaseCommand, CommandError

from clowder_account.models import Company
from clowder_server.emailer import send_alert
from clowder_server.models import Alert, Ping

class Command(BaseCommand):
    help = 'Checks and sends alerts'

    def handle(self, *args, **options):

        # delete old pings
        for company in Company.objects.all():
            pings_by_name = Ping.objects.filter(company=company).distinct('name')

            if not pings_by_name:
                continue

            max_per_ping = 2000 / len(pings_by_name)

            for name in pings_by_name:
                pings = Ping.objects.filter(company=company, name=name).order_by('-create')[:max_per_ping]
                pings = list(pings.values_list("id", flat=True))
                Ping.objects.filter(company=company, name=name).exclude(pk__in=pings).delete()

        # send alerts
        alerts = Alert.objects.filter(notify_at__lte=datetime.datetime.now)
        for alert in alerts:
            send_alert(alert.company, alert.name)
            alert.notify_at = None
            alert.save()
{'fraction_non_alphanumeric': 0.09268707482993198, 'fraction_numerical': 0.002976190476190476, 'mean_word_length': 2.705511811023622, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6713282', 'n_tokens_mistral': 709, 'n_tokens_neox': 671, 'n_words': 147}