🗑️ Remove realm preload to fix bugs
This commit is contained in:
parent
ed73b40bf5
commit
d9d6b81ac3
@ -206,7 +206,7 @@ func joinChannel(c *fiber.Ctx) error {
|
|||||||
var channel models.Channel
|
var channel models.Channel
|
||||||
if err := database.C.Where(&models.Channel{
|
if err := database.C.Where(&models.Channel{
|
||||||
Alias: alias,
|
Alias: alias,
|
||||||
}).Preload("Realm").First(&channel).Error; err != nil {
|
}).First(&channel).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
} else if _, _, err := services.GetAvailableChannel(channel.ID, user); err == nil {
|
} else if _, _, err := services.GetAvailableChannel(channel.ID, user); err == nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, "you already joined the channel")
|
return fiber.NewError(fiber.StatusBadRequest, "you already joined the channel")
|
||||||
|
@ -92,7 +92,7 @@ func GetChannelAliasAvailability(alias string) error {
|
|||||||
|
|
||||||
func GetChannel(id uint) (models.Channel, error) {
|
func GetChannel(id uint) (models.Channel, error) {
|
||||||
var channel models.Channel
|
var channel models.Channel
|
||||||
tx := database.C.Where("id = ?", id).Preload("Realm")
|
tx := database.C.Where("id = ?", id)
|
||||||
tx = PreloadDirectChannelMembers(tx)
|
tx = PreloadDirectChannelMembers(tx)
|
||||||
if err := tx.First(&channel).Error; err != nil {
|
if err := tx.First(&channel).Error; err != nil {
|
||||||
return channel, err
|
return channel, err
|
||||||
@ -103,7 +103,7 @@ func GetChannel(id uint) (models.Channel, error) {
|
|||||||
|
|
||||||
func GetChannelWithAlias(alias string, realmId ...uint) (models.Channel, error) {
|
func GetChannelWithAlias(alias string, realmId ...uint) (models.Channel, error) {
|
||||||
var channel models.Channel
|
var channel models.Channel
|
||||||
tx := database.C.Where(models.Channel{Alias: alias}).Preload("Realm")
|
tx := database.C.Where(models.Channel{Alias: alias})
|
||||||
if len(realmId) > 0 {
|
if len(realmId) > 0 {
|
||||||
tx = tx.Where("realm_id = ?", realmId)
|
tx = tx.Where("realm_id = ?", realmId)
|
||||||
} else {
|
} else {
|
||||||
@ -178,7 +178,7 @@ func ListChannel(user *authm.Account, realmId ...uint) ([]models.Channel, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
var channels []models.Channel
|
var channels []models.Channel
|
||||||
tx := database.C.Preload("Realm")
|
tx := database.C
|
||||||
tx = tx.Where("id IN ? OR is_public = true", idRange)
|
tx = tx.Where("id IN ? OR is_public = true", idRange)
|
||||||
if len(realmId) > 0 {
|
if len(realmId) > 0 {
|
||||||
tx = tx.Where("realm_id = ?", realmId)
|
tx = tx.Where("realm_id = ?", realmId)
|
||||||
@ -195,7 +195,7 @@ func ListChannel(user *authm.Account, realmId ...uint) ([]models.Channel, error)
|
|||||||
|
|
||||||
func ListChannelWithUser(user authm.Account, realmId ...uint) ([]models.Channel, error) {
|
func ListChannelWithUser(user authm.Account, realmId ...uint) ([]models.Channel, error) {
|
||||||
var channels []models.Channel
|
var channels []models.Channel
|
||||||
tx := database.C.Where(&models.Channel{AccountID: user.ID}).Preload("Realm")
|
tx := database.C.Where(&models.Channel{AccountID: user.ID})
|
||||||
if len(realmId) > 0 {
|
if len(realmId) > 0 {
|
||||||
tx = tx.Where("realm_id = ?", realmId)
|
tx = tx.Where("realm_id = ?", realmId)
|
||||||
}
|
}
|
||||||
@ -222,7 +222,7 @@ func ListAvailableChannel(tx *gorm.DB, user authm.Account, realmId ...uint) ([]m
|
|||||||
return item.ChannelID
|
return item.ChannelID
|
||||||
})
|
})
|
||||||
|
|
||||||
tx = tx.Preload("Realm").Where("id IN ?", idx)
|
tx = tx.Where("id IN ?", idx)
|
||||||
if len(realmId) > 0 {
|
if len(realmId) > 0 {
|
||||||
tx = tx.Where("realm_id = ?", realmId)
|
tx = tx.Where("realm_id = ?", realmId)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user