perf: 提升后端高并发承载能力
This commit is contained in:
@@ -6,15 +6,14 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"hightube/internal/db"
|
||||
"hightube/internal/model"
|
||||
)
|
||||
|
||||
// GetMyRoom returns the room details for the currently authenticated user
|
||||
func GetMyRoom(c *gin.Context) {
|
||||
userID, _ := c.Get("user_id")
|
||||
|
||||
var room model.Room
|
||||
if err := db.DB.Where("user_id = ?", userID).First(&room).Error; err != nil {
|
||||
room, err := db.LoadRoomByUserID(userID.(uint))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "Room not found"})
|
||||
return
|
||||
}
|
||||
@@ -29,9 +28,8 @@ func GetMyRoom(c *gin.Context) {
|
||||
|
||||
// GetActiveRooms returns a list of all currently active live rooms
|
||||
func GetActiveRooms(c *gin.Context) {
|
||||
var rooms []model.Room
|
||||
// Fetch rooms where is_active is true
|
||||
if err := db.DB.Where("is_active = ?", true).Find(&rooms).Error; err != nil {
|
||||
rooms, err := db.ListActiveRooms()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch active rooms"})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user