Skip to content

Commit a9c7052

Browse files
committed
Fix for RAND()
1 parent ce3250e commit a9c7052

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/main/scala/photoprism/slideshow/main.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ object PhotoprismSlideshowApp extends cask.MainRoutes{
123123
def randomPhoto(categories: String) = {
124124

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

128129
ds.run:
129130
val photo = (sql"""
@@ -133,9 +134,9 @@ object PhotoprismSlideshowApp extends cask.MainRoutes{
133134
INNER JOIN photos_albums pa ON pa.photo_uid = p.photo_uid
134135
INNER JOIN albums a ON a.album_uid = pa.album_uid
135136
WHERE a.album_type = 'album'
136-
AND a.album_category IN (${categoriesList.mkString("'", "','", "'")})
137+
AND a.album_category IN (${input(0)}, ${input(1)}, ${input(2)}, ${input(3)}, ${input(4)}, ${input(5)}, ${input(6)})
137138
AND p.photo_type = 'image'
138-
ORDER BY ${sqlRandomFunction} LIMIT 1""".read[Photo]).headOption.getOrElse(Photo("INVALID_PHOTO","INVALID PHOTO","","",""))
139+
ORDER BY RAND() LIMIT 1""".read[Photo]).headOption.getOrElse(Photo("INVALID_PHOTO","INVALID PHOTO","","",""))
139140
cask.Response(
140141
s"""
141142
{
@@ -153,6 +154,7 @@ object PhotoprismSlideshowApp extends cask.MainRoutes{
153154

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

157159
ds.run:
158160
val photo = (sql"""
@@ -162,9 +164,9 @@ object PhotoprismSlideshowApp extends cask.MainRoutes{
162164
INNER JOIN photos_albums pa ON pa.photo_uid = p.photo_uid
163165
INNER JOIN albums a ON a.album_uid = pa.album_uid
164166
WHERE a.album_type = 'album'
165-
AND a.album_category IN (${categoriesList.mkString("'", "','", "'")})
167+
AND a.album_category IN (${input(0)}, ${input(1)}, ${input(2)}, ${input(3)}, ${input(4)}, ${input(5)}, ${input(6)})
166168
AND p.photo_type = 'image'
167-
ORDER BY ${sqlRandomFunction} LIMIT 1""".read[Photo]).headOption.getOrElse(Photo("INVALID_PHOTO","INVALID PHOTO","","",""))
169+
ORDER BY RAND() LIMIT 1""".read[Photo]).headOption.getOrElse(Photo("INVALID_PHOTO","INVALID PHOTO","","",""))
168170
cask.Response(
169171
doctype("html")(
170172
html(

0 commit comments

Comments
 (0)