mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Add oshash support (#667)
This commit is contained in:
@@ -41,6 +41,16 @@ WHERE scenes_tags.tag_id = ?
|
||||
GROUP BY scenes_tags.scene_id
|
||||
`
|
||||
|
||||
var countScenesForMissingChecksumQuery = `
|
||||
SELECT id FROM scenes
|
||||
WHERE scenes.checksum is null
|
||||
`
|
||||
|
||||
var countScenesForMissingOSHashQuery = `
|
||||
SELECT id FROM scenes
|
||||
WHERE scenes.oshash is null
|
||||
`
|
||||
|
||||
type SceneQueryBuilder struct{}
|
||||
|
||||
func NewSceneQueryBuilder() SceneQueryBuilder {
|
||||
@@ -50,9 +60,9 @@ func NewSceneQueryBuilder() SceneQueryBuilder {
|
||||
func (qb *SceneQueryBuilder) Create(newScene Scene, tx *sqlx.Tx) (*Scene, error) {
|
||||
ensureTx(tx)
|
||||
result, err := tx.NamedExec(
|
||||
`INSERT INTO scenes (checksum, path, title, details, url, date, rating, o_counter, size, duration, video_codec,
|
||||
`INSERT INTO scenes (oshash, checksum, path, title, details, url, date, rating, o_counter, size, duration, video_codec,
|
||||
audio_codec, format, width, height, framerate, bitrate, studio_id, created_at, updated_at)
|
||||
VALUES (:checksum, :path, :title, :details, :url, :date, :rating, :o_counter, :size, :duration, :video_codec,
|
||||
VALUES (:oshash, :checksum, :path, :title, :details, :url, :date, :rating, :o_counter, :size, :duration, :video_codec,
|
||||
:audio_codec, :format, :width, :height, :framerate, :bitrate, :studio_id, :created_at, :updated_at)
|
||||
`,
|
||||
newScene,
|
||||
@@ -178,6 +188,12 @@ func (qb *SceneQueryBuilder) FindByChecksum(checksum string) (*Scene, error) {
|
||||
return qb.queryScene(query, args, nil)
|
||||
}
|
||||
|
||||
func (qb *SceneQueryBuilder) FindByOSHash(oshash string) (*Scene, error) {
|
||||
query := "SELECT * FROM scenes WHERE oshash = ? LIMIT 1"
|
||||
args := []interface{}{oshash}
|
||||
return qb.queryScene(query, args, nil)
|
||||
}
|
||||
|
||||
func (qb *SceneQueryBuilder) FindByPath(path string) (*Scene, error) {
|
||||
query := selectAll(sceneTable) + "WHERE path = ? LIMIT 1"
|
||||
args := []interface{}{path}
|
||||
@@ -231,6 +247,16 @@ func (qb *SceneQueryBuilder) CountByTagID(tagID int) (int, error) {
|
||||
return runCountQuery(buildCountQuery(countScenesForTagQuery), args)
|
||||
}
|
||||
|
||||
// CountMissingChecksum returns the number of scenes missing a checksum value.
|
||||
func (qb *SceneQueryBuilder) CountMissingChecksum() (int, error) {
|
||||
return runCountQuery(buildCountQuery(countScenesForMissingChecksumQuery), []interface{}{})
|
||||
}
|
||||
|
||||
// CountMissingOSHash returns the number of scenes missing an oshash value.
|
||||
func (qb *SceneQueryBuilder) CountMissingOSHash() (int, error) {
|
||||
return runCountQuery(buildCountQuery(countScenesForMissingOSHashQuery), []interface{}{})
|
||||
}
|
||||
|
||||
func (qb *SceneQueryBuilder) Wall(q *string) ([]*Scene, error) {
|
||||
s := ""
|
||||
if q != nil {
|
||||
@@ -267,7 +293,7 @@ func (qb *SceneQueryBuilder) Query(sceneFilter *SceneFilterType, findFilter *Fin
|
||||
`
|
||||
|
||||
if q := findFilter.Q; q != nil && *q != "" {
|
||||
searchColumns := []string{"scenes.title", "scenes.details", "scenes.path", "scenes.checksum", "scene_markers.title"}
|
||||
searchColumns := []string{"scenes.title", "scenes.details", "scenes.path", "scenes.oshash", "scenes.checksum", "scene_markers.title"}
|
||||
clause, thisArgs := getSearchBinding(searchColumns, *q, false)
|
||||
query.addWhere(clause)
|
||||
query.addArg(thisArgs...)
|
||||
@@ -543,6 +569,32 @@ func (qb *SceneQueryBuilder) UpdateFormat(id int, format string, tx *sqlx.Tx) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qb *SceneQueryBuilder) UpdateOSHash(id int, oshash string, tx *sqlx.Tx) error {
|
||||
ensureTx(tx)
|
||||
_, err := tx.Exec(
|
||||
`UPDATE scenes SET oshash = ? WHERE scenes.id = ? `,
|
||||
oshash, id,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qb *SceneQueryBuilder) UpdateChecksum(id int, checksum string, tx *sqlx.Tx) error {
|
||||
ensureTx(tx)
|
||||
_, err := tx.Exec(
|
||||
`UPDATE scenes SET checksum = ? WHERE scenes.id = ? `,
|
||||
checksum, id,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qb *SceneQueryBuilder) UpdateSceneCover(sceneID int, cover []byte, tx *sqlx.Tx) error {
|
||||
ensureTx(tx)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user