Skip to content

Commit

Permalink
trying to fix random
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-gs committed Sep 16, 2024
1 parent 12f288a commit dfad147
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sbt.lib.mkSbtDerivation {
inherit pkgs;

pname = "photoprism-slideshow";
version = "0.2.3";
version = "0.2.4";

depsSha256 = "sha256-SdrAk1e0YN5yWEpx0j9lflNbjuxf2damPKXb/yM6erc=";

Expand Down
11 changes: 5 additions & 6 deletions src/main/scala/photoprism/slideshow/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ object PhotoprismSlideshowApp extends cask.MainRoutes{
def randomPhoto(categories: String) = {

// Ugly hack for IN condition
val categoriesList = categories.split(",").map(_.trim).filter(_.nonEmpty).toList
val input = (0 to 6).map(i => categoriesList.lift(i).getOrElse("TO_BE_IGNORED"))

val categoriesList = categories.split(",").map(_.trim).filter(_.nonEmpty).toList

ds.run:
val photo = (sql"""
Expand All @@ -135,7 +133,7 @@ object PhotoprismSlideshowApp extends cask.MainRoutes{
INNER JOIN photos_albums pa ON pa.photo_uid = p.photo_uid
INNER JOIN albums a ON a.album_uid = pa.album_uid
WHERE a.album_type = 'album'
AND a.album_category IN (${input(0)}, ${input(1)}, ${input(2)}, ${input(3)}, ${input(4)}, ${input(5)}, ${input(6)})
AND a.album_category IN (${categoriesList.mkString("'", "','", "'")})
AND p.photo_type = 'image'
ORDER BY ${sqlRandomFunction} LIMIT 1""".read[Photo]).headOption.getOrElse(Photo("INVALID_PHOTO","INVALID PHOTO","","",""))
cask.Response(
Expand All @@ -155,7 +153,8 @@ object PhotoprismSlideshowApp extends cask.MainRoutes{

// Ugly hack for IN condition
val categoriesList = categories.split(",").map(_.trim).filter(_.nonEmpty).toList
val input = (0 to 6).map(i => categoriesList.lift(i).getOrElse("TO_BE_IGNORED"))

categoriesList.join(",")


ds.run:
Expand All @@ -166,7 +165,7 @@ object PhotoprismSlideshowApp extends cask.MainRoutes{
INNER JOIN photos_albums pa ON pa.photo_uid = p.photo_uid
INNER JOIN albums a ON a.album_uid = pa.album_uid
WHERE a.album_type = 'album'
AND a.album_category IN (${input(0)}, ${input(1)}, ${input(2)}, ${input(3)}, ${input(4)}, ${input(5)}, ${input(6)})
AND a.album_category IN (${categoriesList.mkString("'", "','", "'")})
AND p.photo_type = 'image'
ORDER BY ${sqlRandomFunction} LIMIT 1""".read[Photo]).headOption.getOrElse(Photo("INVALID_PHOTO","INVALID PHOTO","","",""))
cask.Response(
Expand Down

0 comments on commit dfad147

Please sign in to comment.