Improve performance of gallery and image queries (#2422)

* Revert to use FindByGalleryID in gallery resolver
* Sort by path in FindByGalleryID
* Optimise queries
This commit is contained in:
WithoutPants
2022-03-25 12:00:51 +11:00
committed by GitHub
parent 2d227edaf9
commit f581687198
5 changed files with 30 additions and 12 deletions

View File

@@ -194,11 +194,20 @@ func getMultiCriterionClause(primaryTable, foreignTable, joinTable, primaryFK, f
switch criterion.Modifier {
case models.CriterionModifierIncludes:
// includes any of the provided ids
whereClause = foreignTable + ".id IN " + getInBinding(len(criterion.Value))
if joinTable != "" {
whereClause = joinTable + "." + foreignFK + " IN " + getInBinding(len(criterion.Value))
} else {
whereClause = foreignTable + ".id IN " + getInBinding(len(criterion.Value))
}
case models.CriterionModifierIncludesAll:
// includes all of the provided ids
whereClause = foreignTable + ".id IN " + getInBinding(len(criterion.Value))
havingClause = "count(distinct " + foreignTable + ".id) IS " + strconv.Itoa(len(criterion.Value))
if joinTable != "" {
whereClause = joinTable + "." + foreignFK + " IN " + getInBinding(len(criterion.Value))
havingClause = "count(distinct " + joinTable + "." + foreignFK + ") IS " + strconv.Itoa(len(criterion.Value))
} else {
whereClause = foreignTable + ".id IN " + getInBinding(len(criterion.Value))
havingClause = "count(distinct " + foreignTable + ".id) IS " + strconv.Itoa(len(criterion.Value))
}
case models.CriterionModifierExcludes:
// excludes all of the provided ids
if joinTable != "" {