Skip to content

Commit

Permalink
Sort scenes by file size (cumulative)
Browse files Browse the repository at this point in the history
  • Loading branch information
cld9x committed Jul 13, 2020
1 parent 2a3ed0e commit b3645eb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
9 changes: 9 additions & 0 deletions pkg/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ func Migrate() {
return nil
},
},
{
ID: "0012-preview-flag",
Migrate: func(tx *gorm.DB) error {
type Scene struct {
TotalFileSize int64 `json:"total_file_size" gorm:"default:0"`
}
return tx.AutoMigrate(Scene{}).Error
},
},
})

if err := m.Migrate(); err != nil {
Expand Down
34 changes: 23 additions & 11 deletions pkg/models/model_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ type Scene struct {
CoverURL string `json:"cover_url"`
SceneURL string `json:"scene_url"`

StarRating float64 `json:"star_rating"`
Favourite bool `json:"favourite" gorm:"default:false"`
Watchlist bool `json:"watchlist" gorm:"default:false"`
IsAvailable bool `json:"is_available" gorm:"default:false"`
IsAccessible bool `json:"is_accessible" gorm:"default:false"`
IsWatched bool `json:"is_watched" gorm:"default:false"`
Cuepoints []SceneCuepoint `json:"cuepoints"`
History []History `json:"history"`
AddedDate time.Time `json:"added_date"`
LastOpened time.Time `json:"last_opened"`
StarRating float64 `json:"star_rating"`
Favourite bool `json:"favourite" gorm:"default:false"`
Watchlist bool `json:"watchlist" gorm:"default:false"`
IsAvailable bool `json:"is_available" gorm:"default:false"`
IsAccessible bool `json:"is_accessible" gorm:"default:false"`
IsWatched bool `json:"is_watched" gorm:"default:false"`
Cuepoints []SceneCuepoint `json:"cuepoints"`
History []History `json:"history"`
AddedDate time.Time `json:"added_date"`
LastOpened time.Time `json:"last_opened"`
TotalFileSize int64 `json:"total_file_size"`

HasVideoPreview bool `json:"has_preview" gorm:"default:false"`
// HasVideoThumbnail bool `json:"has_video_thumbnail" gorm:"default:false"`
Expand Down Expand Up @@ -200,9 +201,11 @@ func (o *Scene) UpdateStatus() {
}

var newestFileDate time.Time
var totalFileSize int64
for j := range files {
totalFileSize = totalFileSize + files[j].Size
if files[j].Exists() {
if files[j].CreatedTime.Before(newestFileDate) || newestFileDate.IsZero() {
if files[j].CreatedTime.After(newestFileDate) || newestFileDate.IsZero() {
newestFileDate = files[j].CreatedTime
}
if !o.IsAccessible {
Expand All @@ -217,6 +220,11 @@ func (o *Scene) UpdateStatus() {
}
}

if totalFileSize != o.TotalFileSize {
o.TotalFileSize = totalFileSize
changed = true
}

if !newestFileDate.Equal(o.AddedDate) && !newestFileDate.IsZero() {
o.AddedDate = newestFileDate
changed = true
Expand Down Expand Up @@ -452,6 +460,10 @@ func QueryScenes(r RequestSceneList, enablePreload bool) ResponseSceneList {
tx = tx.Order("release_date desc")
case "release_asc":
tx = tx.Order("release_date asc")
case "total_file_size_desc":
tx = tx.Order("total_file_size desc")
case "total_file_size_asc":
tx = tx.Order("total_file_size asc")
case "rating_desc":
tx = tx.
Where("star_rating > ?", 0).
Expand Down
2 changes: 2 additions & 0 deletions ui/src/views/scenes/Filters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<option value="release_asc">↑ {{$t("Release date")}}</option>
<option value="added_desc">↓ {{$t("File added date")}}</option>
<option value="added_asc">↑ {{$t("File added date")}}</option>
<option value="total_file_size_desc">↓ {{$t("File size")}}</option>
<option value="total_file_size_asc">↑ {{$t("File size")}}</option>
<option value="rating_desc">↓ {{$t("Rating")}}</option>
<option value="rating_asc">↑ {{$t("Rating")}}</option>
<option value="scene_added_desc">↓ {{$t("Scene added date")}}</option>
Expand Down

0 comments on commit b3645eb

Please sign in to comment.