Skip to content

Commit 2f9cd48

Browse files
fstachurastephenfin
andcommitted
views: Add a new covering index for patch table
The new index uses project_id as the first key. This is important, as it seems that almost all web queries filter over project_id. The index also includes the submission date sorted descending, as this is the default sorting key for the patches list. Co-authored-by: Stephen Finucane <stephen@that.guru>
1 parent a5484a3 commit 2f9cd48

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 6.0.6 on 2026-08-13 00:14
2+
3+
from django.conf import settings
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
('patchwork', '0048_series_dependencies'),
10+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
11+
]
12+
13+
operations = [
14+
migrations.AddIndex(
15+
model_name='patch',
16+
index=models.Index(
17+
fields=[
18+
'project',
19+
'archived',
20+
'-date',
21+
'state',
22+
'delegate',
23+
'submitter',
24+
'id',
25+
],
26+
name='patch_covering_idx_default',
27+
),
28+
),
29+
]

‎patchwork/models.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,20 @@ class Meta:
736736
],
737737
name='patch_covering_idx',
738738
),
739+
# Keep date before state to preserve ordering across states.
740+
# Include id explicitly for index-only scans on PostgreSQL.
741+
models.Index(
742+
fields=[
743+
'project',
744+
'archived',
745+
'-date',
746+
'state',
747+
'delegate',
748+
'submitter',
749+
'id',
750+
],
751+
name='patch_covering_idx_default',
752+
),
739753
]
740754

741755

0 commit comments

Comments
 (0)