Skip to content

Commit

Permalink
remove scene counts when querying for heresphere/deo
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Sep 3, 2023
1 parent d0c4e77 commit 2a4dc56
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
18 changes: 10 additions & 8 deletions pkg/api/deovr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import (
"github.com/emicklei/go-restful/v3"
"github.com/markphelps/optional"
"github.com/tidwall/gjson"
"golang.org/x/crypto/bcrypt"

"github.com/xbapps/xbvr/pkg/common"
"github.com/xbapps/xbvr/pkg/config"
"github.com/xbapps/xbvr/pkg/models"
"github.com/xbapps/xbvr/pkg/session"
"golang.org/x/crypto/bcrypt"
)

type DeoLibrary struct {
Expand Down Expand Up @@ -285,8 +286,8 @@ func (i DeoVRResource) getDeoFile(req *restful.Request, resp *restful.Response)
var file models.File
db.Where(&models.File{ID: uint(fileId)}).First(&file)

var height = file.VideoHeight
var width = file.VideoWidth
height := file.VideoHeight
width := file.VideoWidth
var sources []DeoSceneEncoding
sources = append(sources, DeoSceneEncoding{
Name: fmt.Sprintf("File 1/1 - %v", humanize.Bytes(uint64(file.Size))),
Expand Down Expand Up @@ -389,9 +390,9 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
var sceneMultiProjection bool = true

for i, file := range videoFiles {
var height = file.VideoHeight
var width = file.VideoWidth
var source = DeoSceneEncoding{
height := file.VideoHeight
width := file.VideoWidth
source := DeoSceneEncoding{
Name: fmt.Sprintf("File %v/%v %vp - %v", i+1, len(videoFiles), file.VideoHeight, humanize.Bytes(uint64(file.Size))),
VideoSources: []DeoSceneVideoSource{
{
Expand Down Expand Up @@ -499,7 +500,7 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
title := scene.Title
thumbnailURL := session.DeoRequestHost + "/img/700x/" + strings.Replace(scene.CoverURL, "://", ":/", -1)

//Passthrough
// Passthrough
var ckdata map[string]interface{}
// nochromaKey := `{"enabled":false,"hasAlpha":false,"h":0,"opacity":0,"s":0,"threshold":0,"v":0}`
chromaKey := gjson.Parse(scene.ChromaKey)
Expand All @@ -512,7 +513,7 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
if !result.Exists() || ckdata["hasAlpha"] == "" {
// if ckdata["."].(map[string]interface{})["hasAlpha"] = "false" || ckdata["."].(map[string]interface{})["hasAlpha"] = "" {

//setting hasAlpha to false
// setting hasAlpha to false
ckdata["hasAlpha"] = "false"
}
// Convert back to JSON string
Expand Down Expand Up @@ -625,6 +626,7 @@ func (i DeoVRResource) getDeoLibrary(req *restful.Request, resp *restful.Respons
r.IsAccessible = optional.NewBool(true)
r.IsAvailable = optional.NewBool(true)
r.Limit = optional.NewInt(10000)
r.Counts = optional.NewBool(false)

q := models.QueryScenes(r, false)
sceneLists = append(sceneLists, DeoListScenes{
Expand Down
1 change: 1 addition & 0 deletions pkg/api/heresphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ func (i HeresphereResource) getHeresphereLibrary(req *restful.Request, resp *res
r.IsAccessible = optional.NewBool(true)
r.IsAvailable = optional.NewBool(true)
r.Limit = optional.NewInt(20000)
r.Counts = optional.NewBool(false)

q := models.QueryScenes(r, false)

Expand Down
25 changes: 15 additions & 10 deletions pkg/models/model_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ type RequestSceneList struct {
DlState optional.String `json:"dlState"`
Limit optional.Int `json:"limit"`
Offset optional.Int `json:"offset"`
Counts optional.Bool `json:"counts"`
IsAvailable optional.Bool `json:"isAvailable"`
IsAccessible optional.Bool `json:"isAccessible"`
IsWatched optional.Bool `json:"isWatched"`
Expand Down Expand Up @@ -1160,12 +1161,14 @@ func QueryScenes(r RequestSceneList, enablePreload bool) ResponseSceneList {
tx = tx.Order("release_date desc")
}

// Count other variations
tx.Group("scenes.scene_id").Where("is_hidden = ?", false).Count(&out.CountAny)
tx.Group("scenes.scene_id").Where("is_available = ?", true).Where("is_accessible = ?", true).Where("is_hidden = ?", false).Count(&out.CountAvailable)
tx.Group("scenes.scene_id").Where("is_available = ?", true).Where("is_hidden = ?", false).Count(&out.CountDownloaded)
tx.Group("scenes.scene_id").Where("is_available = ?", false).Where("is_hidden = ?", false).Count(&out.CountNotDownloaded)
tx.Group("scenes.scene_id").Where("is_hidden = ?", true).Count(&out.CountHidden)
if r.Counts.OrElse(true) {
// Count other variations
tx.Group("scenes.scene_id").Where("is_hidden = ?", false).Count(&out.CountAny)
tx.Group("scenes.scene_id").Where("is_available = ?", true).Where("is_accessible = ?", true).Where("is_hidden = ?", false).Count(&out.CountAvailable)
tx.Group("scenes.scene_id").Where("is_available = ?", true).Where("is_hidden = ?", false).Count(&out.CountDownloaded)
tx.Group("scenes.scene_id").Where("is_available = ?", false).Where("is_hidden = ?", false).Count(&out.CountNotDownloaded)
tx.Group("scenes.scene_id").Where("is_hidden = ?", true).Count(&out.CountHidden)
}

// Apply avail/accessible after counting
if r.IsAvailable.Present() {
Expand All @@ -1182,10 +1185,12 @@ func QueryScenes(r RequestSceneList, enablePreload bool) ResponseSceneList {
tx = tx.Where("is_hidden = ?", false)
}

// Count totals for selection
tx.
Group("scenes.scene_id").
Count(&out.Results)
if r.Counts.OrElse(true) {
// Count totals for selection
tx.
Group("scenes.scene_id").
Count(&out.Results)
}

// Get scenes
tx.
Expand Down

0 comments on commit 2a4dc56

Please sign in to comment.