Fix movies sorting, scene studio editing (#1478)

* Fix movies:sort_by->scenes_count, scene:edit->remove studio
This commit is contained in:
bnkai 2021-06-04 02:21:17 +03:00 committed by GitHub
parent 2ce4d9f0d8
commit ad0a9d0707
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 9 deletions

View file

@ -107,7 +107,7 @@ func (m *Manager) notifyNewJob(j *Job) {
} }
func (m *Manager) nextID() int { func (m *Manager) nextID() int {
m.lastID += 1 m.lastID++
return m.lastID return m.lastID
} }

View file

@ -99,7 +99,7 @@ func (p *Progress) Increment() {
defer p.mutex.Unlock() defer p.mutex.Unlock()
if p.processed < p.total { if p.processed < p.total {
p.processed += 1 p.processed++
p.calculatePercent() p.calculatePercent()
} }
} }

View file

@ -210,12 +210,14 @@ func (qb *movieQueryBuilder) getMovieSort(findFilter *models.FindFilterType) str
direction = findFilter.GetDirection() direction = findFilter.GetDirection()
} }
// #943 - override name sorting to use natural sort switch sort {
if sort == "name" { case "name": // #943 - override name sorting to use natural sort
return " ORDER BY " + getColumn("movies", sort) + " COLLATE NATURAL_CS " + direction return " ORDER BY " + getColumn("movies", sort) + " COLLATE NATURAL_CS " + direction
case "scenes_count": // generic getSort won't work for this
return getCountSort(movieTable, moviesScenesTable, movieIDColumn, direction)
default:
return getSort(sort, direction, "movies")
} }
return getSort(sort, direction, "movies")
} }
func (qb *movieQueryBuilder) queryMovie(query string, args []interface{}) (*models.Movie, error) { func (qb *movieQueryBuilder) queryMovie(query string, args []interface{}) (*models.Movie, error) {

View file

@ -186,6 +186,35 @@ func queryMovie(t *testing.T, sqb models.MovieReader, movieFilter *models.MovieF
return movies return movies
} }
func TestMovieQuerySorting(t *testing.T) {
sort := "scenes_count"
direction := models.SortDirectionEnumDesc
findFilter := models.FindFilterType{
Sort: &sort,
Direction: &direction,
}
withTxn(func(r models.Repository) error {
sqb := r.Movie()
movies := queryMovie(t, sqb, nil, &findFilter)
// scenes should be in same order as indexes
firstMovie := movies[0]
assert.Equal(t, movieIDs[movieIdxWithScene], firstMovie.ID)
// sort in descending order
direction = models.SortDirectionEnumAsc
movies = queryMovie(t, sqb, nil, &findFilter)
lastMovie := movies[len(movies)-1]
assert.Equal(t, movieIDs[movieIdxWithScene], lastMovie.ID)
return nil
})
}
func TestMovieUpdateMovieImages(t *testing.T) { func TestMovieUpdateMovieImages(t *testing.T) {
if err := withTxn(func(r models.Repository) error { if err := withTxn(func(r models.Repository) error {
mqb := r.Movie() mqb := r.Movie()

View file

@ -6,7 +6,7 @@ import (
// Note that the public API returns "" instead. // Note that the public API returns "" instead.
func TestOshashEmpty(t *testing.T) { func TestOshashEmpty(t *testing.T) {
var size int64 = 0 var size int64
head := make([]byte, chunkSize) head := make([]byte, chunkSize)
tail := make([]byte, chunkSize) tail := make([]byte, chunkSize)
want := "0000000000000000" want := "0000000000000000"
@ -23,7 +23,7 @@ func TestOshashEmpty(t *testing.T) {
func TestOshashCollisions(t *testing.T) { func TestOshashCollisions(t *testing.T) {
buf1 := []byte("this is dumb") buf1 := []byte("this is dumb")
buf2 := []byte("dumb is this") buf2 := []byte("dumb is this")
var size int64 = int64(len(buf1)) var size = int64(len(buf1))
head := make([]byte, chunkSize) head := make([]byte, chunkSize)
tail1 := make([]byte, chunkSize) tail1 := make([]byte, chunkSize)

View file

@ -618,7 +618,7 @@ export const SceneEditPanel: React.FC<IProps> = ({
onSelect={(items) => onSelect={(items) =>
formik.setFieldValue( formik.setFieldValue(
"studio_id", "studio_id",
items.length > 0 ? items[0]?.id : undefined items.length > 0 ? items[0]?.id : null
) )
} }
ids={formik.values.studio_id ? [formik.values.studio_id] : []} ids={formik.values.studio_id ? [formik.values.studio_id] : []}