Skip to content

Commit

Permalink
fetch only as much as necessary for deovr lists
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Sep 3, 2023
1 parent 30bb424 commit d036903
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pkg/api/deovr.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type DeoListScenes struct {

type DeoListItem struct {
Title string `json:"title"`
VideoLength int `json:"videoLength"`
VideoLength uint `json:"videoLength"`
ThumbnailURL string `json:"thumbnailUrl"`
VideoURL string `json:"video_url"`
}
Expand Down Expand Up @@ -625,13 +625,11 @@ func (i DeoVRResource) getDeoLibrary(req *restful.Request, resp *restful.Respons
if err := json.Unmarshal([]byte(savedPlaylists[i].SearchParams), &r); err == nil {
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)
summaries := models.QuerySceneSummaries(r)
sceneLists = append(sceneLists, DeoListScenes{
Name: savedPlaylists[i].Name,
List: scenesToDeoList(req, q.Scenes),
List: scenesToDeoList(req, summaries),
})
}
}
Expand All @@ -656,15 +654,16 @@ func (i DeoVRResource) getDeoLibrary(req *restful.Request, resp *restful.Respons
})
}

func scenesToDeoList(req *restful.Request, scenes []models.Scene) []DeoListItem {
func scenesToDeoList(req *restful.Request, scenes []models.SceneSummary) []DeoListItem {
setDeoPlayerHost(req)

list := make([]DeoListItem, 0)
for i := range scenes {
thumbnailURL := fmt.Sprintf("%v/img/700x/%v", session.DeoRequestHost, strings.Replace(scenes[i].CoverURL, "://", ":/", -1))

var thumbnailURL string
if config.Config.Interfaces.DeoVR.RenderHeatmaps && scenes[i].IsScripted {
thumbnailURL = fmt.Sprintf("%v/imghm/%d/%v", session.DeoRequestHost, scenes[i].ID, strings.Replace(scenes[i].CoverURL, "://", ":/", -1))
} else {
thumbnailURL = fmt.Sprintf("%v/img/700x/%v", session.DeoRequestHost, strings.Replace(scenes[i].CoverURL, "://", ":/", -1))
}

item := DeoListItem{
Expand Down Expand Up @@ -695,7 +694,7 @@ func filesToDeoList(req *restful.Request, files []models.File) []DeoListItem {
}
item := DeoListItem{
Title: files[i].Filename,
VideoLength: int(files[i].VideoDuration),
VideoLength: uint(files[i].VideoDuration),
ThumbnailURL: session.DeoRequestHost + "/ui/images/blank.png",
VideoURL: fmt.Sprintf("%v/deovr/file/%v%v", session.DeoRequestHost, files[i].ID, dnt),
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/models/model_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,26 @@ func QuerySceneIDs(r RequestSceneList) []string {
return ids
}

type SceneSummary struct {
ID uint
Title string
Duration uint
CoverURL string
IsScripted bool
}

func QuerySceneSummaries(r RequestSceneList) []SceneSummary {
db, _ := GetDB()
defer db.Close()

_, finalTx := queryScenes(db, r)

var summaries []SceneSummary
finalTx.Select("scenes.id, title, duration, cover_url, is_scripted").Scan(&summaries)

return summaries
}

func queryScenes(db *gorm.DB, r RequestSceneList) (*gorm.DB, *gorm.DB) {
tx := db.Model(&Scene{})

Expand Down Expand Up @@ -1006,6 +1026,9 @@ func queryScenes(db *gorm.DB, r RequestSceneList) (*gorm.DB, *gorm.DB) {
tx = tx.Order("release_date desc")
}

// Add second order to keep things stable in case of ties
tx = tx.Order("scenes.id asc")

preCountTx := tx.Group("scenes.scene_id")
tx = tx.Group("scenes.scene_id")

Expand Down

0 comments on commit d036903

Please sign in to comment.