Skip to content

Commit

Permalink
Add index on BaseTarget.created to speed up load time of large DBs
Browse files Browse the repository at this point in the history
We currently sort on the created field of BaseTarget, which causes
performance issues when there are a large number of BaseTargets.

In a database with 6 million rows, this reduced the time for the SQL
count(*) from ~800ms to ~100ms, significantly speeding up page load
time.

Note that this does NOT solve #598 but it does help a little.
  • Loading branch information
Fingel committed Feb 5, 2025
1 parent 4a46922 commit 61f8a78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tom_targets/base_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ class BaseTarget(models.Model):
)
created = models.DateTimeField(
auto_now_add=True, verbose_name='Time Created',
help_text='The time which this target was created in the TOM database.'
help_text='The time which this target was created in the TOM database.',
db_index=True
)
modified = models.DateTimeField(
auto_now=True, verbose_name='Last Modified',
Expand Down
18 changes: 18 additions & 0 deletions tom_targets/migrations/0023_alter_basetarget_created.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.18 on 2025-02-05 21:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tom_targets', '0022_persistentshare'),
]

operations = [
migrations.AlterField(
model_name='basetarget',
name='created',
field=models.DateTimeField(auto_now_add=True, db_index=True, help_text='The time which this target was created in the TOM database.', verbose_name='Time Created'),
),
]

0 comments on commit 61f8a78

Please sign in to comment.