mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Autotag optimisation (#2368)
* Add duration to autotag finish message * No sorting scene/image/gallery where not specified * Use an LRU cache for sqlite regexp function * Compile path separator regex once * Cache objects with single letter first names * Move finished auto-tag log * Add more verbose logging * Add new changelog
This commit is contained in:
@@ -486,16 +486,13 @@ func galleryAverageResolutionCriterionHandler(qb *galleryQueryBuilder, resolutio
|
||||
}
|
||||
|
||||
func (qb *galleryQueryBuilder) getGallerySort(findFilter *models.FindFilterType) string {
|
||||
var sort string
|
||||
var direction string
|
||||
if findFilter == nil {
|
||||
sort = "path"
|
||||
direction = "ASC"
|
||||
} else {
|
||||
sort = findFilter.GetSort("path")
|
||||
direction = findFilter.GetDirection()
|
||||
if findFilter == nil || findFilter.Sort == nil || *findFilter.Sort == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
sort := findFilter.GetSort("path")
|
||||
direction := findFilter.GetDirection()
|
||||
|
||||
switch sort {
|
||||
case "images_count":
|
||||
return getCountSort(galleryTable, galleriesImagesTable, galleryIDColumn, direction)
|
||||
|
||||
@@ -517,8 +517,8 @@ INNER JOIN (` + valuesClause + `) t ON t.column2 = pt.tag_id
|
||||
}
|
||||
|
||||
func (qb *imageQueryBuilder) getImageSort(findFilter *models.FindFilterType) string {
|
||||
if findFilter == nil {
|
||||
return " ORDER BY images.path ASC "
|
||||
if findFilter == nil || findFilter.Sort == nil || *findFilter.Sort == "" {
|
||||
return ""
|
||||
}
|
||||
sort := findFilter.GetSort("title")
|
||||
direction := findFilter.GetDirection()
|
||||
|
||||
@@ -21,12 +21,6 @@ WHERE performers_tags.tag_id = ?
|
||||
GROUP BY performers_tags.performer_id
|
||||
`
|
||||
|
||||
// KNOWN ISSUE: using \p{L} to find single unicode character names results in
|
||||
// very slow queries.
|
||||
// Suggested solution will be to cache single-character names and not include it
|
||||
// in the autotag query.
|
||||
const singleFirstCharacterRegex = `^[\w][.\-_ ]`
|
||||
|
||||
type performerQueryBuilder struct {
|
||||
repository
|
||||
}
|
||||
@@ -189,9 +183,6 @@ func (qb *performerQueryBuilder) QueryForAutoTag(words []string) ([]*models.Perf
|
||||
var whereClauses []string
|
||||
var args []interface{}
|
||||
|
||||
whereClauses = append(whereClauses, "name regexp ?")
|
||||
args = append(args, singleFirstCharacterRegex)
|
||||
|
||||
for _, w := range words {
|
||||
whereClauses = append(whereClauses, "name like ?")
|
||||
args = append(args, w+"%")
|
||||
|
||||
@@ -760,8 +760,7 @@ func (qb *sceneQueryBuilder) getDefaultSceneSort() string {
|
||||
}
|
||||
|
||||
func (qb *sceneQueryBuilder) setSceneSort(query *queryBuilder, findFilter *models.FindFilterType) {
|
||||
if findFilter == nil {
|
||||
query.sortAndPagination += qb.getDefaultSceneSort()
|
||||
if findFilter == nil || findFilter.Sort == nil || *findFilter.Sort == "" {
|
||||
return
|
||||
}
|
||||
sort := findFilter.GetSort("title")
|
||||
|
||||
@@ -144,10 +144,6 @@ func (qb *studioQueryBuilder) QueryForAutoTag(words []string) ([]*models.Studio,
|
||||
var whereClauses []string
|
||||
var args []interface{}
|
||||
|
||||
// always include names that begin with a single character
|
||||
whereClauses = append(whereClauses, "studios.name regexp ? OR COALESCE(studio_aliases.alias, '') regexp ?")
|
||||
args = append(args, singleFirstCharacterRegex, singleFirstCharacterRegex)
|
||||
|
||||
for _, w := range words {
|
||||
ww := w + "%"
|
||||
whereClauses = append(whereClauses, "studios.name like ?")
|
||||
|
||||
@@ -235,10 +235,6 @@ func (qb *tagQueryBuilder) QueryForAutoTag(words []string) ([]*models.Tag, error
|
||||
var whereClauses []string
|
||||
var args []interface{}
|
||||
|
||||
// always include names that begin with a single character
|
||||
whereClauses = append(whereClauses, "tags.name regexp ? OR COALESCE(tag_aliases.alias, '') regexp ?")
|
||||
args = append(args, singleFirstCharacterRegex, singleFirstCharacterRegex)
|
||||
|
||||
for _, w := range words {
|
||||
ww := w + "%"
|
||||
whereClauses = append(whereClauses, "tags.name like ?")
|
||||
|
||||
Reference in New Issue
Block a user