Fix link account always update cache record

This commit is contained in:
LittleSheep 2024-03-26 22:49:12 +08:00
parent 97e1d1f87e
commit 2116e5b390
3 changed files with 12 additions and 7 deletions

View File

@ -1,23 +1,23 @@
package grpc package grpc
import ( import (
pwpb "git.solsynth.dev/hydrogen/identity/pkg/grpc/proto" idpb "git.solsynth.dev/hydrogen/identity/pkg/grpc/proto"
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
"github.com/spf13/viper" "github.com/spf13/viper"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
var Notify pwpb.NotifyClient var Notify idpb.NotifyClient
var Auth pwpb.AuthClient var Auth idpb.AuthClient
func ConnectPassport() error { func ConnectPassport() error {
addr := viper.GetString("identity.grpc_endpoint") addr := viper.GetString("identity.grpc_endpoint")
if conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials())); err != nil { if conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials())); err != nil {
return err return err
} else { } else {
Notify = pwpb.NewNotifyClient(conn) Notify = idpb.NewNotifyClient(conn)
Auth = pwpb.NewAuthClient(conn) Auth = idpb.NewAuthClient(conn)
} }
return nil return nil

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"reflect"
"time" "time"
"git.solsynth.dev/hydrogen/identity/pkg/grpc/proto" "git.solsynth.dev/hydrogen/identity/pkg/grpc/proto"
@ -37,6 +38,7 @@ func LinkAccount(userinfo *proto.Userinfo) (models.Account, error) {
return account, err return account, err
} }
prev := account
account.Name = userinfo.Name account.Name = userinfo.Name
account.Nick = userinfo.Nick account.Nick = userinfo.Nick
account.Avatar = userinfo.Avatar account.Avatar = userinfo.Avatar
@ -44,7 +46,10 @@ func LinkAccount(userinfo *proto.Userinfo) (models.Account, error) {
account.Description = userinfo.GetDescription() account.Description = userinfo.GetDescription()
account.EmailAddress = userinfo.Email account.EmailAddress = userinfo.Email
err := database.C.Save(&account).Error var err error
if !reflect.DeepEqual(prev, account) {
err = database.C.Save(&account).Error
}
return account, err return account, err
} }

View File

@ -8,7 +8,7 @@ secret = "LtTjzAGFLshwXhN4ZD4nG5KlMv1MWcsvfv03TSZYnT1VhiAnLIZFTnHUwR0XhGgi"
content = "uploads" content = "uploads"
[debug] [debug]
database = true database = false
print_routes = false print_routes = false
[identity] [identity]