Files
bugsink/snappea/models.py
Klaas van Schelven 86e8c4318b Add indexes on fields on which we order and vice versa
Triggered by issue_event_list being more than 5s on "emu" (my 1,500,000 event
test-machine). Reason: sorting those events on non-indexed field. Switching
to a field-with-index solved it.

I then analysed (grepped) for "ordering" and "order_by" and set indexes
accordingly and more or less indiscriminately (i.e. even on tables that are
assumed to have relatively few rows, such as Project & Team).
2025-02-04 21:19:24 +01:00

33 lines
820 B
Python

import os
from django.db import models
from .settings import get_settings
from . import thread_uuid
class Task(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
task_name = models.CharField(max_length=255)
args = models.TextField(null=False, default='[]')
kwargs = models.TextField(null=False, default='{}')
def __str__(self):
return self.task_name
class Meta:
indexes = [
models.Index(fields=['created_at']),
]
def wakeup_server():
wakeup_file = os.path.join(get_settings().WAKEUP_CALLS_DIR, thread_uuid)
if not os.path.exists(get_settings().WAKEUP_CALLS_DIR):
os.makedirs(get_settings().WAKEUP_CALLS_DIR, exist_ok=True)
if not os.path.exists(wakeup_file):
with open(wakeup_file, "w"):
pass