2023-01-12 12:42:16 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-10-26 13:38:31 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/cmd/cachemanager"
|
2023-05-04 12:36:17 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/pkg/logs"
|
|
|
|
"github.com/fthvgb1/wp-go/app/pkg/models"
|
2023-01-18 15:02:59 +00:00
|
|
|
"github.com/fthvgb1/wp-go/model"
|
2023-01-12 12:42:16 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getUserById(a ...any) (r models.Users, err error) {
|
|
|
|
ctx := a[0].(context.Context)
|
|
|
|
uid := a[1].(uint64)
|
|
|
|
r, err = model.FindOneById[models.Users](ctx, uid)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetUserByName(ctx context.Context, username string) (models.Users, error) {
|
|
|
|
return usersNameCache.GetCache(ctx, username, time.Second, ctx, username)
|
|
|
|
}
|
|
|
|
|
2023-01-21 13:13:33 +00:00
|
|
|
func GetAllUsername(ctx context.Context) (map[string]struct{}, error) {
|
|
|
|
return allUsernameCache.GetCache(ctx, time.Second, ctx)
|
|
|
|
}
|
|
|
|
|
2023-01-12 12:42:16 +00:00
|
|
|
func GetUserById(ctx context.Context, uid uint64) models.Users {
|
2023-10-26 13:38:31 +00:00
|
|
|
r, err := cachemanager.Get[models.Users]("userData", ctx, uid, time.Second)
|
2023-04-07 14:59:07 +00:00
|
|
|
logs.IfError(err, "get user", uid)
|
2023-01-12 12:42:16 +00:00
|
|
|
return r
|
|
|
|
}
|