Speed up tag count queries (#570)

* Speed up tag count queries
* Add test for marker CountByTagID

Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
InfiniteTF
2020-05-24 08:18:02 +02:00
committed by GitHub
parent 95a6d3ea2f
commit 32fce9ac6f
3 changed files with 37 additions and 12 deletions

View File

@@ -7,12 +7,10 @@ import (
"strconv"
)
const sceneMarkersForTagQuery = `
SELECT scene_markers.* FROM scene_markers
const countSceneMarkersForTagQuery = `
SELECT scene_markers.id FROM scene_markers
LEFT JOIN scene_markers_tags as tags_join on tags_join.scene_marker_id = scene_markers.id
LEFT JOIN tags on tags_join.tag_id = tags.id
LEFT JOIN tags AS ptj ON ptj.id = scene_markers.primary_tag_id
WHERE tags.id = ? OR ptj.id = ?
WHERE tags_join.tag_id = ? OR scene_markers.primary_tag_id = ?
GROUP BY scene_markers.id
`
@@ -87,7 +85,7 @@ func (qb *SceneMarkerQueryBuilder) FindBySceneID(sceneID int, tx *sqlx.Tx) ([]*S
func (qb *SceneMarkerQueryBuilder) CountByTagID(tagID int) (int, error) {
args := []interface{}{tagID, tagID}
return runCountQuery(buildCountQuery(sceneMarkersForTagQuery), args)
return runCountQuery(buildCountQuery(countSceneMarkersForTagQuery), args)
}
func (qb *SceneMarkerQueryBuilder) GetMarkerStrings(q *string, sort *string) ([]*MarkerStringsResultType, error) {