Enha: roomlistupdate only on change; heartbeat every 2s

This commit is contained in:
Grail Finder
2025-07-10 11:35:56 +03:00
parent 85edb2d0ce
commit c946c07542
2 changed files with 10 additions and 5 deletions

View File

@ -57,6 +57,7 @@ func (cm *CronManager) CleanupRooms() {
}
return
}
roomListChange := false
for _, room := range rooms {
players, err := cm.repo.PlayerListByRoom(ctx, room.ID)
if err != nil {
@ -71,6 +72,7 @@ func (cm *CronManager) CleanupRooms() {
if err := cm.repo.SettingsDeleteByRoomID(ctx, room.ID); err != nil {
cm.log.Error("failed to delete settings for empty room", "room_id", room.ID, "err", err)
}
roomListChange = true
continue
}
creatorInRoom := false
@ -120,6 +122,7 @@ func (cm *CronManager) CleanupRooms() {
if err := cm.repo.SettingsDeleteByRoomID(ctx, room.ID); err != nil {
cm.log.Error("failed to delete settings for room", "room_id", room.ID, "reason", reason, "err", err)
}
roomListChange = true
// Move to the next room
continue
}
@ -127,9 +130,11 @@ func (cm *CronManager) CleanupRooms() {
if err := tx.Commit(); err != nil {
cm.log.Error("failed to commit transaction", "err", err)
}
broker.Notifier.Notifier <- broker.NotificationEvent{
EventName: models.NotifyRoomListUpdate,
Payload: "",
if roomListChange {
broker.Notifier.Notifier <- broker.NotificationEvent{
EventName: models.NotifyRoomListUpdate,
Payload: "",
}
}
}