From dba37736362d188a804beea817c697c95241134a Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Wed, 6 Apr 2016 22:12:29 +1000 Subject: [PATCH] Adds db indices --- .../migrations/0012_auto_20160406_1212.py | 49 +++++++++++++++++++ registrasion/models.py | 27 ++++++++-- 2 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 registrasion/migrations/0012_auto_20160406_1212.py diff --git a/registrasion/migrations/0012_auto_20160406_1212.py b/registrasion/migrations/0012_auto_20160406_1212.py new file mode 100644 index 00000000..61a27ed1 --- /dev/null +++ b/registrasion/migrations/0012_auto_20160406_1212.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.2 on 2016-04-06 12:12 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('registrasion', '0011_auto_20160401_0943'), + ] + + operations = [ + migrations.AlterField( + model_name='cart', + name='active', + field=models.BooleanField(db_index=True, default=True), + ), + migrations.AlterField( + model_name='cart', + name='released', + field=models.BooleanField(db_index=True, default=False), + ), + migrations.AlterField( + model_name='cart', + name='time_last_updated', + field=models.DateTimeField(db_index=True), + ), + migrations.AlterField( + model_name='category', + name='order', + field=models.PositiveIntegerField(db_index=True, verbose_name='Display order'), + ), + migrations.AlterField( + model_name='product', + name='order', + field=models.PositiveIntegerField(db_index=True, verbose_name='Display order'), + ), + migrations.AlterField( + model_name='productitem', + name='quantity', + field=models.PositiveIntegerField(db_index=True), + ), + migrations.AlterIndexTogether( + name='cart', + index_together=set([('active', 'released'), ('released', 'user'), ('active', 'user'), ('active', 'time_last_updated')]), + ), + ] diff --git a/registrasion/models.py b/registrasion/models.py index 1e0e23de..941ebef5 100644 --- a/registrasion/models.py +++ b/registrasion/models.py @@ -99,6 +99,7 @@ class Category(models.Model): ) order = models.PositiveIntegerField( verbose_name=("Display order"), + db_index=True, ) render_type = models.IntegerField( choices=CATEGORY_RENDER_TYPES, @@ -147,6 +148,7 @@ class Product(models.Model): ) order = models.PositiveIntegerField( verbose_name=("Display order"), + db_index=True, ) @@ -313,6 +315,7 @@ class VoucherDiscount(DiscountBase): Voucher, on_delete=models.CASCADE, verbose_name=_("Voucher"), + db_index=True, ) @@ -458,17 +461,33 @@ class Cart(models.Model): ''' Represents a set of product items that have been purchased, or are pending purchase. ''' + class Meta: + index_together = [ + ("active", "time_last_updated"), + ("active", "released"), + ("active", "user"), + ("released", "user"), + ] + def __str__(self): return "%d rev #%d" % (self.id, self.revision) user = models.ForeignKey(User) # ProductItems (foreign key) vouchers = models.ManyToManyField(Voucher, blank=True) - time_last_updated = models.DateTimeField() + time_last_updated = models.DateTimeField( + db_index=True, + ) reservation_duration = models.DurationField() revision = models.PositiveIntegerField(default=1) - active = models.BooleanField(default=True) - released = models.BooleanField(default=False) # Refunds etc + active = models.BooleanField( + default=True, + db_index=True, + ) + released = models.BooleanField( + default=False, + db_index=True + ) # Refunds etc @classmethod def reserved_carts(cls): @@ -492,7 +511,7 @@ class ProductItem(models.Model): cart = models.ForeignKey(Cart) product = models.ForeignKey(Product) - quantity = models.PositiveIntegerField() + quantity = models.PositiveIntegerField(db_index=True) @python_2_unicode_compatible