Skip to content

Commit

Permalink
fix: exclude hidden scenes from Actor average rating (xbapps#1503)
Browse files Browse the repository at this point in the history
  • Loading branch information
toshski authored Nov 24, 2023
1 parent 624b025 commit 1ca8d10
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/models/model_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ func QueryActors(r RequestActorList, enablePreload bool) ResponseActorList {
tx = tx.Where("actors.star_rating <= ?", r.MaxRating.OrElse(5))
}
if r.MinSceneRating.OrElse(0) > 0 {
tx = tx.Where("(select AVG(s.star_rating) from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id and s.star_rating > 0 ) >= ?", r.MinSceneRating.OrElse(0))
tx = tx.Where("(select AVG(s.star_rating) from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id and s.star_rating > 0 and is_hidden=0) >= ?", r.MinSceneRating.OrElse(0))
}
if r.MaxSceneRating.OrElse(5) < 5 {
tx = tx.Where("(select AVG(s.star_rating) from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id and s.star_rating > 0 ) <= ?", r.MaxSceneRating.OrElse(50))
tx = tx.Where("(select AVG(s.star_rating) from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id and s.star_rating > 0 and is_hidden=0) <= ?", r.MaxSceneRating.OrElse(50))
}
var sites []string
var mustHaveSites []string
Expand Down Expand Up @@ -432,7 +432,7 @@ func QueryActors(r RequestActorList, enablePreload bool) ResponseActorList {
Order("actors.star_rating asc")
case "scene_rating_desc":
tx = tx.
Order("(select AVG(s.star_rating) from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id and s.star_rating > 0 ) desc, (select count(*) from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id and s.star_rating > 0 ) desc, (select count(*) from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id) desc")
Order("(select AVG(s.star_rating) from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id and s.star_rating > 0 and is_hidden=0) desc, (select count(*) from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id and s.star_rating > 0 and is_hidden=0) desc, (select count(*) from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id) desc")
case "scene_release_desc":
tx = tx.
Order("IFNULL((select max(s.release_date) from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id),'1970-01-01') DESC, actors.avail_count desc, actors.`count` desc")
Expand Down Expand Up @@ -493,7 +493,7 @@ func QueryActors(r RequestActorList, enablePreload bool) ResponseActorList {
out.Offset = offset

tx = tx.Select(`distinct actors.*,
(select AVG(s.star_rating) scene_avg from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id and s.star_rating > 0 ) as scene_rating_average
(select AVG(s.star_rating) scene_avg from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id and s.star_rating > 0 and is_hidden=0) as scene_rating_average
`)

tx.Limit(limit).
Expand Down Expand Up @@ -531,7 +531,7 @@ func (o *Actor) GetIfExistByPKWithSceneAvg(id uint) error {

tx := db.Model(&Actor{})
tx = tx.Select(`actors.*,
(select AVG(s.star_rating) scene_avg from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id and s.star_rating > 0 ) as scene_rating_average`)
(select AVG(s.star_rating) scene_avg from scene_cast sc join scenes s on s.id=sc.scene_id where sc.actor_id =actors.id and s.star_rating > 0 and is_hidden=0) as scene_rating_average`)

return tx.
Preload("Scenes", func(db *gorm.DB) *gorm.DB {
Expand Down

0 comments on commit 1ca8d10

Please sign in to comment.