Skip to content

Commit

Permalink
Add missing DB indexes on Project model #569
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <[email protected]>
  • Loading branch information
tdruez committed May 17, 2023
1 parent 7b54a4d commit 3cf3d58
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,50 @@ class Migration(migrations.Migration):
name="scanpipe_co_detecte_f3f97d_idx",
),
),
# Extra fields alterations and index additions
migrations.AlterField(
model_name="discoveredpackage",
name="package_uid",
field=models.CharField(
blank=True,
help_text="Unique identifier for this package.",
max_length=1024,
),
),
migrations.AlterField(
model_name="project",
name="created_date",
field=models.DateTimeField(
auto_now_add=True, help_text="Creation date for this project."
),
),
migrations.AlterField(
model_name="project",
name="name",
field=models.CharField(
help_text="Name for this project.", max_length=100, unique=True
),
),
migrations.AddIndex(
model_name="discoveredpackage",
index=models.Index(
fields=["package_uid"], name="scanpipe_di_package_379c99_idx"
),
),
migrations.AddIndex(
model_name="project",
index=models.Index(
fields=["-created_date"], name="scanpipe_pr_created_258a96_idx"
),
),
migrations.AddIndex(
model_name="project",
index=models.Index(
fields=["is_archived"], name="scanpipe_pr_is_arch_6af64f_idx"
),
),
migrations.AddIndex(
model_name="project",
index=models.Index(fields=["name"], name="scanpipe_pr_name_c81038_idx"),
),
]
9 changes: 6 additions & 3 deletions scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,10 @@ class Project(UUIDPKModel, ExtraDataFieldMixin, models.Model):

created_date = models.DateTimeField(
auto_now_add=True,
db_index=True,
help_text=_("Creation date for this project."),
)
name = models.CharField(
unique=True,
db_index=True,
max_length=100,
help_text=_("Name for this project."),
)
Expand All @@ -485,6 +483,11 @@ class Project(UUIDPKModel, ExtraDataFieldMixin, models.Model):

class Meta:
ordering = ["-created_date"]
indexes = [
models.Index(fields=["-created_date"]),
models.Index(fields=["is_archived"]),
models.Index(fields=["name"]),
]

def __str__(self):
return self.name
Expand Down Expand Up @@ -2264,7 +2267,6 @@ class DiscoveredPackage(
package_uid = models.CharField(
max_length=1024,
blank=True,
db_index=True,
help_text=_("Unique identifier for this package."),
)
keywords = models.JSONField(default=list, blank=True)
Expand All @@ -2279,6 +2281,7 @@ class Meta:
models.Index(fields=["namespace"]),
models.Index(fields=["name"]),
models.Index(fields=["filename"]),
models.Index(fields=["package_uid"]),
models.Index(fields=["primary_language"]),
models.Index(fields=["declared_license_expression"]),
models.Index(fields=["other_license_expression"]),
Expand Down

0 comments on commit 3cf3d58

Please sign in to comment.