Skip to content

Commit

Permalink
fix: restore indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed Nov 12, 2024
1 parent 7ab13a2 commit ec0872b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 4.2.16 on 2024-11-12 09:10

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('uni_ticket', '0025_remove_ticket_uni_ticket__id_1dfb83_idx_and_more'),
]

operations = [
migrations.RemoveIndex(
model_name='ticket',
name='uni_ticket__id_694f6e_idx',
),
migrations.RemoveIndex(
model_name='ticketassignment',
name='uni_ticket__ticket__c4313e_idx',
),
migrations.AlterField(
model_name='ticket',
name='is_closed',
field=models.BooleanField(db_index=True, default=False),
),
migrations.AddIndex(
model_name='ticketassignment',
index=models.Index(fields=['office_id', 'follow'], name='uni_ticket__office__f42ab9_idx'),
),
]
15 changes: 8 additions & 7 deletions uniticket/uni_ticket/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ class Ticket(SavedFormContent):
)
input_module = models.ForeignKey(
TicketCategoryModule, on_delete=models.PROTECT)
is_closed = models.BooleanField(default=False)
is_closed = models.BooleanField(default=False, db_index=True)
closed_date = models.DateTimeField(blank=True, null=True)
assigned_date = models.DateTimeField(blank=True, null=True, db_index=True)
closed_by = models.ForeignKey(
Expand Down Expand Up @@ -503,7 +503,6 @@ class Meta:
]
verbose_name = _("Ticket")
verbose_name_plural = _("Ticket")
indexes = [models.Index(fields=["id", "is_closed"])]

@property
def taken_date(self):
Expand Down Expand Up @@ -1187,7 +1186,7 @@ class TicketAssignment(TimeStampedModel):
class Meta:
unique_together = ("ticket", "office")
ordering = ["created"]
indexes = [models.Index(fields=["ticket_id", "office_id", "follow"])]
indexes = [models.Index(fields=["office_id", "follow"])]
verbose_name = _("Competenza Ticket")
verbose_name_plural = _("Competenza Ticket")

Expand Down Expand Up @@ -1218,13 +1217,15 @@ def get_ticket_per_structure(structure,
if not priority_first:
ordering_list.remove("ticket__priority")

from django.db.models import Count
ticket_assignments = TicketAssignment.objects\
.filter(
q_base
).values_list("ticket__pk", flat=True)\
.order_by(*ordering_list)\
.distinct()

).values("ticket__pk")\
.annotate(dcount=Count('ticket__pk'))\
.order_by(*ordering_list)
# .distinct()
print(ticket_assignments)
return ticket_assignments

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion uniticket/uni_ticket/views/datatables.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def fill_data(self):

tickets = []
for entry in self.fqs:
t = Ticket.objects.filter(pk=entry)\
t = Ticket.objects.filter(pk=entry['ticket__pk'])\
.select_related('created_by',
'compiled_by',
'input_module__ticket_category',
Expand Down

0 comments on commit ec0872b

Please sign in to comment.