perf: tweak some queries in mkpkglists

We can omit the "distinct" from some queries
because constraints in the DB ensure uniqueness:

* Groups sub-query
PackageGroup: Primary key makes "PackageID" + "GroupID" unique
Groups: Unique index on "Name" column
-> Technically we can't have a package with the same group-name twice

* Licenses sub-query:
PackageLicense -> Primary key makes "PackageID" + "LicenseID" unique
Licenses -> Unique index on "Name" column
-> Technically we can't have a package with the same license-name twice

* Keywords sub-query:
PackageKeywords -> Primary key makes "PackageBaseID" + "KeywordID" unique
(And a Package can only have one PackageBase)
Keywords -> Unique index on "Name" column
-> Technically we can't have a package with the same Keyword twice

* Packages main-query:
We join PackageBases and Users on their primary key columns
(which are guaranteed to be unique)
-> There is no way we could end up with more than one record for a Package

Signed-off-by: moson-mo <mo-son@mailbox.org>
This commit is contained in:
moson-mo 2022-10-31 18:00:39 +01:00
parent 286834bab1
commit 5669821b29
No known key found for this signature in database
GPG key ID: 4A4760AB4EE15296

View file

@ -94,7 +94,7 @@ def get_extended_fields():
models.PackageDependency.DepName.label("Name"), models.PackageDependency.DepName.label("Name"),
models.PackageDependency.DepCondition.label("Cond"), models.PackageDependency.DepCondition.label("Cond"),
) )
.distinct() .distinct() # A package could have the same dependency multiple times
.order_by("Name"), .order_by("Name"),
# PackageRelation # PackageRelation
db.query(models.PackageRelation) db.query(models.PackageRelation)
@ -105,7 +105,7 @@ def get_extended_fields():
models.PackageRelation.RelName.label("Name"), models.PackageRelation.RelName.label("Name"),
models.PackageRelation.RelCondition.label("Cond"), models.PackageRelation.RelCondition.label("Cond"),
) )
.distinct() .distinct() # A package could have the same relation multiple times
.order_by("Name"), .order_by("Name"),
# Groups # Groups
db.query(models.PackageGroup) db.query(models.PackageGroup)
@ -116,7 +116,6 @@ def get_extended_fields():
models.Group.Name.label("Name"), models.Group.Name.label("Name"),
literal(str()).label("Cond"), literal(str()).label("Cond"),
) )
.distinct()
.order_by("Name"), .order_by("Name"),
# Licenses # Licenses
db.query(models.PackageLicense) db.query(models.PackageLicense)
@ -127,7 +126,6 @@ def get_extended_fields():
models.License.Name.label("Name"), models.License.Name.label("Name"),
literal(str()).label("Cond"), literal(str()).label("Cond"),
) )
.distinct()
.order_by("Name"), .order_by("Name"),
# Keywords # Keywords
db.query(models.PackageKeyword) db.query(models.PackageKeyword)
@ -140,7 +138,6 @@ def get_extended_fields():
models.PackageKeyword.Keyword.label("Name"), models.PackageKeyword.Keyword.label("Name"),
literal(str()).label("Cond"), literal(str()).label("Cond"),
) )
.distinct()
.order_by("Name"), .order_by("Name"),
# Co-Maintainer # Co-Maintainer
db.query(models.PackageComaintainer) db.query(models.PackageComaintainer)
@ -155,7 +152,7 @@ def get_extended_fields():
models.User.Username.label("Name"), models.User.Username.label("Name"),
literal(str()).label("Cond"), literal(str()).label("Cond"),
) )
.distinct() .distinct() # A package could have the same co-maintainer multiple times
.order_by("Name"), .order_by("Name"),
] ]
query = subqueries[0].union_all(*subqueries[1:]) query = subqueries[0].union_all(*subqueries[1:])
@ -230,7 +227,6 @@ def _main():
PackageBase.SubmittedTS.label("FirstSubmitted"), PackageBase.SubmittedTS.label("FirstSubmitted"),
PackageBase.ModifiedTS.label("LastModified"), PackageBase.ModifiedTS.label("LastModified"),
) )
.distinct()
.order_by("Name") .order_by("Name")
) )