From ce5b09953e5d0ce91d9c019086e8a80679c0f216 Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 2 Mar 2024 09:56:48 +0300 Subject: [PATCH] appdata-debug --- server/memorystore/providers/redis/store.go | 27 ++++++++++++++++++--- server/resolvers/login.go | 2 ++ server/resolvers/session.go | 2 ++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index 4ed66c4..5035609 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -219,15 +219,34 @@ func (c *provider) GetBoolStoreEnvVariable(key string) (bool, error) { return data == "1", nil } +type UserProfile struct { + ID string `json:"id"` + // Add other fields as necessary +} + // GetUserAppDataFromRedis retrieves user profile and follows from Redis, combines them into a JSON format, // and assigns the JSON string to the provided user's ID. func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { - // Retrieve user data from Redis - userProfile := c.store.Get(c.ctx, fmt.Sprintf(`user:%s:author`, userId)) - userFollows := c.store.Get(c.ctx, fmt.Sprintf(`user:%s:follows`, userId)) + // Retrieve user data from Redis + userProfileString := c.store.Get(c.ctx, fmt.Sprintf(`user:%s:author`, userId)) + + // Parse userProfileString into a UserProfile struct + var userProfile UserProfile + err := json.Unmarshal([]byte(userProfileString), &userProfile) + if err != nil { + return "", err + } + + // Use userProfile.ID here if necessary + authorId := userProfile.ID + userFollowsAuthors := c.store.Get(c.ctx, fmt.Sprintf(`author:%s:follows-authors`, authorId)) + userFollowsTopics := c.store.Get(c.ctx, fmt.Sprintf(`author:%s:follows-topics`, authorId)) + userFollowers := c.store.Get(c.ctx, fmt.Sprintf(`author:%s:followers`, authorId)) // Combine user data into a JSON string - combinedData := fmt.Sprintf(`{"profile": %s, "follows": %s}`, userProfile, userFollows) + combinedData := fmt.Sprintf( + `{"profile": %s, "authors": %s, "topics": %s, "followers": %s}`, + userProfile, userFollowsAuthors, userFollowsTopics, userFollowers) return combinedData, nil } diff --git a/server/resolvers/login.go b/server/resolvers/login.go index b79ddfe..0aeee67 100644 --- a/server/resolvers/login.go +++ b/server/resolvers/login.go @@ -320,6 +320,8 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes if err == nil { // Assign the combined data to the provided pointer user.AppData = &appData + } else { + log.Printf("Error getting author's redis cache: %v", err) } res = &model.AuthResponse{ diff --git a/server/resolvers/session.go b/server/resolvers/session.go index f359782..2305cf2 100644 --- a/server/resolvers/session.go +++ b/server/resolvers/session.go @@ -94,6 +94,8 @@ func SessionResolver(ctx context.Context, params *model.SessionQueryInput) (*mod if err == nil { // Assign the combined data to the provided pointer user.AppData = &appData + } else { + log.Printf("Error getting author's redis cache: %v", err) } res = &model.AuthResponse{