diff --git a/shynet/analytics/migrations/0004_auto_20210328_1514.py b/shynet/analytics/migrations/0004_auto_20210328_1514.py new file mode 100644 index 0000000..45afe74 --- /dev/null +++ b/shynet/analytics/migrations/0004_auto_20210328_1514.py @@ -0,0 +1,38 @@ +# Generated by Django 3.1.7 on 2021-03-28 19:14 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('analytics', '0003_auto_20200502_1227'), + ] + + operations = [ + migrations.AlterField( + model_name='hit', + name='last_seen', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + migrations.AlterField( + model_name='hit', + name='start_time', + field=models.DateTimeField(db_index=True, default=django.utils.timezone.now), + ), + migrations.AlterField( + model_name='session', + name='last_seen', + field=models.DateTimeField(db_index=True, default=django.utils.timezone.now), + ), + migrations.AlterField( + model_name='session', + name='start_time', + field=models.DateTimeField(db_index=True, default=django.utils.timezone.now), + ), + migrations.AddIndex( + model_name='session', + index=models.Index(fields=['service', '-last_seen'], name='analytics_s_service_10bb96_idx'), + ), + ] diff --git a/shynet/analytics/models.py b/shynet/analytics/models.py index 52391fc..b16b289 100644 --- a/shynet/analytics/models.py +++ b/shynet/analytics/models.py @@ -22,7 +22,7 @@ class Session(models.Model): # Time start_time = models.DateTimeField(default=timezone.now, db_index=True) - last_seen = models.DateTimeField(default=timezone.now) + last_seen = models.DateTimeField(default=timezone.now, db_index=True) # Core request information user_agent = models.TextField() @@ -53,6 +53,7 @@ class Session(models.Model): ordering = ["-start_time"] indexes = [ models.Index(fields=["service", "-start_time"]), + models.Index(fields=["service", "-last_seen"]), models.Index(fields=["service", "identifier"]), ]