♻️ Rebuilt cache with the new cache system from nexus

This commit is contained in:
2025-03-29 13:15:20 +08:00
parent c8e8104d5d
commit a4c6e9a905
15 changed files with 188 additions and 752 deletions

View File

@ -172,7 +172,7 @@ func editUserinfo(c *fiber.Ctx) error {
}
services.AddEvent(user.ID, "profile.edit", nil, c.IP(), c.Get(fiber.HeaderUserAgent))
services.InvalidAuthCacheWithUser(account.ID)
services.InvalidUserAuthCache(account.ID)
return c.SendStatus(fiber.StatusOK)
}
@ -197,7 +197,7 @@ func updateAccountLanguage(c *fiber.Ctx) error {
}
services.AddEvent(user.ID, "profile.edit.language", nil, c.IP(), c.Get(fiber.HeaderUserAgent))
services.InvalidAuthCacheWithUser(user.ID)
services.InvalidUserAuthCache(user.ID)
user.Language = data.Language

View File

@ -30,7 +30,7 @@ func setAvatar(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
} else {
services.AddEvent(user.ID, "profile.edit.avatar", nil, c.IP(), c.Get(fiber.HeaderUserAgent))
services.InvalidAuthCacheWithUser(user.ID)
services.InvalidUserAuthCache(user.ID)
}
if og != nil && len(*og) > 0 {
@ -66,7 +66,7 @@ func setBanner(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
} else {
services.AddEvent(user.ID, "profile.edit.banner", nil, c.IP(), c.Get(fiber.HeaderUserAgent))
services.InvalidAuthCacheWithUser(user.ID)
services.InvalidUserAuthCache(user.ID)
}
if og != nil && len(*og) > 0 {

View File

@ -50,7 +50,7 @@ func getNotificationPreference(c *fiber.Ctx) error {
return err
}
user := c.Locals("user").(models.Account)
notification, err := services.GetNotificationPreference(user)
notification, err := services.GetNotifyPreference(user)
if err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
@ -72,7 +72,7 @@ func updateNotificationPreference(c *fiber.Ctx) error {
return err
}
notification, err := services.UpdateNotificationPreference(user, data.Config)
notification, err := services.UpdateNotifyPreference(user, data.Config)
if err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else {

View File

@ -1,18 +1,13 @@
package api
import (
"context"
"fmt"
"strconv"
"strings"
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
localCache "git.solsynth.dev/hypernet/passport/pkg/internal/cache"
"git.solsynth.dev/hypernet/passport/pkg/internal/web/exts"
"github.com/eko/gocache/lib/v4/cache"
"github.com/eko/gocache/lib/v4/marshaler"
"gorm.io/gorm"
"git.solsynth.dev/hypernet/passport/pkg/internal/database"
"git.solsynth.dev/hypernet/passport/pkg/internal/services"
@ -22,48 +17,15 @@ import (
func getOtherUserinfo(c *fiber.Ctx) error {
alias := c.Params("alias")
cacheManager := cache.New[any](localCache.S)
marshal := marshaler.New(cacheManager)
ctx := context.Background()
if val, err := marshal.Get(ctx, services.GetAccountCacheKey(alias), new(models.Account)); err == nil {
return c.JSON(*val.(*models.Account))
}
tx := database.C.Where("name = ?", alias)
var account models.Account
var err error
numericId, err := strconv.Atoi(alias)
if err == nil {
if val, err := marshal.Get(ctx, services.GetAccountCacheKey(numericId), new(models.Account)); err == nil {
return c.JSON(*val.(*models.Account))
}
tx = tx.Or("id = ?", numericId)
account, err = services.GetAccountForEnd(uint(numericId))
} else {
account, err = services.GetAccountForEnd(alias)
}
var account models.Account
if err := tx.
Preload("Profile").
Preload("Badges", func(db *gorm.DB) *gorm.DB {
return db.Order("badges.is_active DESC, badges.type DESC")
}).
First(&account).Error; err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
}
groups, err := services.GetUserAccountGroup(account)
if err != nil {
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("unable to get account groups: %v", err))
}
for _, group := range groups {
for k, v := range group.PermNodes {
if _, ok := account.PermNodes[k]; !ok {
account.PermNodes[k] = v
}
}
}
services.CacheAccount(account)
return c.JSON(account)
}