fix: Make Redis optional for city rooms online count
- Handle Redis connection errors gracefully - Return rooms even if Redis is unavailable - This fixes 500 error on /api/city/rooms endpoint
This commit is contained in:
@@ -1165,8 +1165,13 @@ async def get_city_rooms(limit: int = 100, offset: int = 0):
|
||||
try:
|
||||
rooms = await repo_city.get_all_rooms(limit=limit, offset=offset)
|
||||
|
||||
# Додати online count (приблизно)
|
||||
online_count = await PresenceRedis.get_online_count()
|
||||
# Додати online count (приблизно) - опціонально, якщо Redis недоступний
|
||||
online_count = 0
|
||||
try:
|
||||
online_count = await PresenceRedis.get_online_count()
|
||||
except Exception as redis_error:
|
||||
logger.warning(f"Redis unavailable for online count: {redis_error}")
|
||||
online_count = 0
|
||||
|
||||
result = []
|
||||
for room in rooms:
|
||||
@@ -1246,6 +1251,15 @@ async def get_city_rooms_api():
|
||||
try:
|
||||
rooms = await repo_city.get_all_rooms(limit=100, offset=0)
|
||||
|
||||
# Отримати online count опціонально (якщо Redis доступний)
|
||||
online_count = 0
|
||||
try:
|
||||
from lib.presence_redis import PresenceRedis
|
||||
online_count = await PresenceRedis.get_online_count()
|
||||
except Exception:
|
||||
# Redis недоступний - не критично
|
||||
pass
|
||||
|
||||
result = []
|
||||
for room in rooms:
|
||||
result.append({
|
||||
@@ -1257,7 +1271,7 @@ async def get_city_rooms_api():
|
||||
"matrix_room_id": room.get("matrix_room_id"),
|
||||
"is_public": room.get("is_public", True),
|
||||
"room_role": room.get("room_role"),
|
||||
"members_online": room.get("members_online") or 0,
|
||||
"members_online": online_count if room.get("is_default") else max(1, online_count // 2),
|
||||
"zone": room.get("zone"),
|
||||
"room_type": room.get("room_type", "city"),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user