Skip to content

Commit

Permalink
fix :: QUEUE MESSAGE CACHE FIX
Browse files Browse the repository at this point in the history
  • Loading branch information
jombidev committed Oct 23, 2024
1 parent d5e131c commit 7b93d85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ class GenerativeImageService(
generated.collect {
when (it) {
is QueueInfoMessage -> {
actor.setGenerating(room.id!!, true, it.position)
actor.setGenerating(room.id!!, it.position)
actor.addQueue(room.id, it.position, true)
println("${room.id}: ${it.position}")
}
is GenerateMessage -> {
actor.setGenerating(room.id!!, false, -1)
actor.addQueue(room.id, -1, true)
actor.clearGenerating(room.id!!)
actor.addQueue(room.id, -1, false)
if (it.result) {
guaranteed = it.image!!
}
Expand Down
14 changes: 9 additions & 5 deletions src/main/kotlin/com/teamapi/palette/ws/actor/SinkActor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ class SinkActor(
}

fun isGenerating(roomId: Long) = generates[roomId]
fun setGenerating(roomId: Long, curr: Boolean, pos: Int) {
val prev = isGenerating(roomId) != null
if (curr != prev) {
if (curr) generates[roomId] = pos
else generates.remove(roomId)
fun setGenerating(roomId: Long, pos: Int) {
synchronized(generates) {
generates.remove(roomId)
generates[roomId] = pos
}
}
fun clearGenerating(roomId: Long) {
synchronized(generates) {
generates.remove(roomId)
}
}

Expand Down

0 comments on commit 7b93d85

Please sign in to comment.