From 2420297c20d08ceb5083d3d3a2ee8f99da44fe8b Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Mon, 18 Mar 2024 00:12:17 -0300 Subject: [PATCH 01/22] feat: branch dev with CI to deploy dev in staging.discour.io --- .gitea/workflows/main.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index 3bdc6a4..3744b44 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -4,7 +4,6 @@ on: [push] jobs: deploy: runs-on: ubuntu-latest - if: github.ref == 'refs/heads/mailgun' steps: - name: Cloning repo uses: actions/checkout@v2 @@ -19,9 +18,18 @@ jobs: id: branch_name run: echo "::set-output name=branch::$(echo ${GITHUB_REF##*/})" - - name: Push to dokku + - name: Push to dokku for main branch + if: steps.branch_name.outputs.branch == 'mailgun' uses: dokku/github-action@master with: branch: 'main' git_remote_url: 'ssh://dokku@v2.discours.io:22/authorizer' + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Push to dokku for dev branch + if: steps.branch_name.outputs.branch == 'dev' + uses: dokku/github-action@master + with: + branch: 'main' + git_remote_url: 'ssh://dokku@staging.discours.io:22/authorizer' ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} \ No newline at end of file From 4990a77786979adaca17b1ec00a5b4de998f17d5 Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Thu, 11 Apr 2024 17:09:38 -0300 Subject: [PATCH 02/22] feat: CI mailgun->v2 and dev->staging --- .gitea/workflows/main.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index 57423b2..3744b44 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -5,7 +5,10 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Cloning repo + uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Get Repo Name id: repo_name @@ -15,9 +18,18 @@ jobs: id: branch_name run: echo "::set-output name=branch::$(echo ${GITHUB_REF##*/})" - - name: Push to dokku + - name: Push to dokku for main branch + if: steps.branch_name.outputs.branch == 'mailgun' uses: dokku/github-action@master with: branch: 'main' git_remote_url: 'ssh://dokku@v2.discours.io:22/authorizer' ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Push to dokku for dev branch + if: steps.branch_name.outputs.branch == 'dev' + uses: dokku/github-action@master + with: + branch: 'main' + git_remote_url: 'ssh://dokku@staging.discours.io:22/authorizer' + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} \ No newline at end of file From cfaf6c49b4de7c6eb8985a5e754ed34d7069405d Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Thu, 11 Apr 2024 17:10:55 -0300 Subject: [PATCH 03/22] feat: CI mailgun->v2 and dev->staging --- .gitea/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index 3744b44..b2cae71 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -25,6 +25,7 @@ jobs: branch: 'main' git_remote_url: 'ssh://dokku@v2.discours.io:22/authorizer' ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + git_push_flags: '--force' - name: Push to dokku for dev branch if: steps.branch_name.outputs.branch == 'dev' @@ -32,4 +33,5 @@ jobs: with: branch: 'main' git_remote_url: 'ssh://dokku@staging.discours.io:22/authorizer' - ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} \ No newline at end of file + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + git_push_flags: '--force' \ No newline at end of file From ca0118df5efdffbb0f2979e14d915537892bbf2b Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Thu, 11 Apr 2024 17:16:39 -0300 Subject: [PATCH 04/22] debug: no force in push to staging --- .gitea/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index be542a9..27205d2 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -32,5 +32,4 @@ jobs: with: branch: 'main' git_remote_url: 'ssh://dokku@staging.discours.io:22/authorizer' - ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} - git_push_flags: '--force' \ No newline at end of file + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} \ No newline at end of file From 42017035fc485eda9528d1dda32b5a5e4df3413a Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 21 May 2024 03:25:15 +0300 Subject: [PATCH 05/22] reimplement-following-data-proxy --- server/memorystore/providers/redis/store.go | 93 ++++++++++++++++----- 1 file changed, 73 insertions(+), 20 deletions(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index 5dc8e88..5ced74b 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -227,42 +227,95 @@ type AuthorProfile struct { // 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. +f func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { - authorProfileString, err := c.store.Get(c.ctx, fmt.Sprintf(`user:%s`, userId)).Result() + // Получаем ID автора из Redis + authorIdString, err := c.store.Get(c.ctx, fmt.Sprintf("user:id:%s", userId)).Result() if err != nil { return "", err } - // Parse authorProfileString into a map + // Преобразуем ID автора из строки в int + var authorId int + err = json.Unmarshal([]byte(authorIdString), &authorId) + if err != nil { + return "", err + } + + // Получаем профиль автора из Redis + authorProfileString, err := c.store.Get(c.ctx, fmt.Sprintf("author:id:%d", authorId)).Result() + if err != nil { + return "", err + } + + // Парсим профиль пользователя в map var authorProfileMap map[string]interface{} err = json.Unmarshal([]byte(authorProfileString), &authorProfileMap) if err != nil { return "", err } - // Combine user data into a JSON string - combinedData := "{" - // Use authorProfileMap["id"] here if necessary - authorId := int(authorProfileMap["id"].(float64)) // convert float64 to int - combinedData += fmt.Sprintf(`"profile": %s`, authorProfileString) - - authorFollowsAuthorsString := c.store.Get(c.ctx, fmt.Sprintf(`author:%d:follows-authors`, authorId)).Val() - if authorFollowsAuthorsString != "" { - combinedData += fmt.Sprintf(`,"authors": %s`, authorFollowsAuthorsString) + // Начинаем сбор данных в общий JSON + combinedData := map[string]interface{}{ + "profile": authorProfileMap, } - authorFollowsTopicsString := c.store.Get(c.ctx, fmt.Sprintf(`author:%d:follows-topics`, authorId)).Val() - if authorFollowsTopicsString != "" { - combinedData += fmt.Sprintf(`,"topics": %s`, authorFollowsTopicsString) + // Получаем подписки автора на других авторов + if authorsObjectsString, err := c.getFollowedObjectsString(fmt.Sprintf("author:follows-authors:%d", authorId), "author:id:%d"); err == nil { + combinedData["authors"] = authorsObjectsString } - authorFollowers := c.store.Get(c.ctx, fmt.Sprintf(`author:%d:followers`, authorId)).Val() - if authorFollowers != "" { - combinedData += fmt.Sprintf(`,"followers": %s`, authorFollowers) + // Получаем подписки автора на темы + if topicsObjectString, err := c.getFollowedObjectsString(fmt.Sprintf("author:follows-topics:%d", authorId), "topic:id:%d"); err == nil { + combinedData["topics"] = topicsObjectString } - combinedData += "}" - // log.Printf("%v", combinedData) + // Получаем подписчиков автора + if authorFollowersObjectsString, err := c.getFollowedObjectsString(fmt.Sprintf("author:followers:%d", authorId), "author:id:%d"); err == nil { + combinedData["followers"] = authorFollowersObjectsString + } - return combinedData, nil + // Преобразуем собранные данные в JSON строку + combinedDataString, err := json.Marshal(combinedData) + if err != nil { + return "", err + } + + return string(combinedDataString), nil +} + +// Универсальная функция для получения объектов по списку ID из Redis +func (c *provider) getFollowedObjectsString(followKey string, objectKeyPattern string) ([]map[string]interface{}, error) { + followsString, err := c.store.Get(c.ctx, followKey).Result() + if err != nil { + if err == redis.Nil { + return []map[string]interface{}{}, nil + } + return nil, err + } + + var ids []int + err = json.Unmarshal([]byte(followsString), &ids) + if err != nil { + return nil, err + } + + objects := make([]map[string]interface{}, 0, len(ids)) + for _, id := range ids { + objectString, err := c.store.Get(c.ctx, fmt.Sprintf(objectKeyPattern, id)).Result() + if err == redis.Nil { + continue + } else if err != nil { + return nil, err + } + + var object map[string]interface{} + err = json.Unmarshal([]byte(objectString), &object) + if err != nil { + return nil, err + } + objects = append(objects, object) + } + + return objects, nil } From 0b823ffc337b009fe44507bed56059a2e8440aa3 Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 21 May 2024 03:31:06 +0300 Subject: [PATCH 06/22] reimplement-following-data-proxy-2 --- server/memorystore/providers/redis/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index 5ced74b..c5c021e 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -227,7 +227,7 @@ type AuthorProfile struct { // 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. -f + func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { // Получаем ID автора из Redis authorIdString, err := c.store.Get(c.ctx, fmt.Sprintf("user:id:%s", userId)).Result() From 32eaff5c5d786cb84ec1add562ed45aa4e6ae354 Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 21 May 2024 03:37:14 +0300 Subject: [PATCH 07/22] reimplement-following-data-proxy-3 --- server/memorystore/providers/redis/store.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index c5c021e..9073b81 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -8,6 +8,8 @@ import ( "github.com/authorizerdev/authorizer/server/constants" log "github.com/sirupsen/logrus" + + "github.com/go-redis/redis/v8" ) var ( @@ -227,7 +229,6 @@ type AuthorProfile struct { // 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) { // Получаем ID автора из Redis authorIdString, err := c.store.Get(c.ctx, fmt.Sprintf("user:id:%s", userId)).Result() From 12af7fc61780c70987c323f7d8ff97cd19f62f1a Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 21 May 2024 03:38:56 +0300 Subject: [PATCH 08/22] reimplement-following-data-proxy-4 --- server/memorystore/providers/redis/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index 9073b81..0aa75d3 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -9,7 +9,7 @@ import ( "github.com/authorizerdev/authorizer/server/constants" log "github.com/sirupsen/logrus" - "github.com/go-redis/redis/v8" + "github.com/redis/go-redis/v9" ) var ( From 693f252ae90d27ec4f5740c38fc101cd21bca692 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 30 May 2024 18:34:25 +0300 Subject: [PATCH 09/22] redis-key --- server/memorystore/providers/redis/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index 0aa75d3..c22335a 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -231,7 +231,7 @@ type AuthorProfile struct { // and assigns the JSON string to the provided user's ID. func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { // Получаем ID автора из Redis - authorIdString, err := c.store.Get(c.ctx, fmt.Sprintf("user:id:%s", userId)).Result() + authorIdString, err := c.store.Get(c.ctx, fmt.Sprintf("author:user:%s", userId)).Result() if err != nil { return "", err } From 76f976937ae8ad504073318c2bb3705361649e51 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 5 Jun 2024 21:20:36 +0300 Subject: [PATCH 10/22] fixed-redis-cache --- server/memorystore/providers/redis/store.go | 15 +-------------- server/resolvers/delete_user.go | 2 +- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index c22335a..90b7ded 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -230,21 +230,8 @@ type AuthorProfile struct { // 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) { - // Получаем ID автора из Redis - authorIdString, err := c.store.Get(c.ctx, fmt.Sprintf("author:user:%s", userId)).Result() - if err != nil { - return "", err - } - - // Преобразуем ID автора из строки в int - var authorId int - err = json.Unmarshal([]byte(authorIdString), &authorId) - if err != nil { - return "", err - } - // Получаем профиль автора из Redis - authorProfileString, err := c.store.Get(c.ctx, fmt.Sprintf("author:id:%d", authorId)).Result() + authorProfileString, err := c.store.Get(c.ctx, fmt.Sprintf("author:user:%d", userId)).Result() if err != nil { return "", err } diff --git a/server/resolvers/delete_user.go b/server/resolvers/delete_user.go index e6ccf62..69acd60 100644 --- a/server/resolvers/delete_user.go +++ b/server/resolvers/delete_user.go @@ -54,7 +54,7 @@ func DeleteUserResolver(ctx context.Context, params model.DeleteUserInput) (*mod // delete otp for given email otp, err := db.Provider.GetOTPByEmail(ctx, refs.StringValue(user.Email)) if err != nil { - log.Infof("No OTP found for email (%s): %v", user.Email, err) + log.Info("No OTP found for email (%s): %v", user.Email, err) // continue } else { err := db.Provider.DeleteOTP(ctx, otp) From b8f5e9ebb908d04226ce0ba60522fb4f43f3b11e Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 5 Jun 2024 21:27:51 +0300 Subject: [PATCH 11/22] fixed-redis-cache-2 --- server/memorystore/providers/redis/store.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index 90b7ded..7a59fa6 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -243,6 +243,12 @@ func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { return "", err } + authorId, ok := authorProfileMap["id"].(int) + if !ok { + fmt.Println("Ошибка: id не найден или неверного типа") + return "", errors.New("id not found or is of incorrect type") + } + // Начинаем сбор данных в общий JSON combinedData := map[string]interface{}{ "profile": authorProfileMap, From 3197154fec8a3c9e7c7c5b5667217eb1d144ede2 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 5 Jun 2024 21:32:10 +0300 Subject: [PATCH 12/22] fixed-redis-cache-3 --- server/memorystore/providers/redis/store.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index 7a59fa6..2765f3d 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -4,6 +4,7 @@ import ( "fmt" "strconv" "time" + "errors" "encoding/json" "github.com/authorizerdev/authorizer/server/constants" From 085faf73e7f7cc80a7bac444b1156e7847a37c1d Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 5 Jun 2024 21:53:59 +0300 Subject: [PATCH 13/22] fixed-redis-cache-5 --- server/memorystore/providers/redis/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index 2765f3d..dd312a3 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -232,7 +232,7 @@ type AuthorProfile struct { // and assigns the JSON string to the provided user's ID. func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { // Получаем профиль автора из Redis - authorProfileString, err := c.store.Get(c.ctx, fmt.Sprintf("author:user:%d", userId)).Result() + authorProfileString, err := c.store.Get(c.ctx, fmt.Sprintf("author:user:%s", userId)).Result() if err != nil { return "", err } From 641c5bc24898f145740a3b43317ed73abf578a2e Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 5 Jun 2024 22:01:24 +0300 Subject: [PATCH 14/22] fixed-redis-debug --- server/memorystore/providers/redis/store.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index dd312a3..a2b7c0e 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -232,8 +232,11 @@ type AuthorProfile struct { // and assigns the JSON string to the provided user's ID. func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { // Получаем профиль автора из Redis - authorProfileString, err := c.store.Get(c.ctx, fmt.Sprintf("author:user:%s", userId)).Result() + rkey := fmt.Sprintf("author:user:%s", userId) + authorProfileString, err := c.store.Get(c.ctx, rkey).Result() if err != nil { + fmt.Println("redis GET: %s", rkey) + fmt.Println("%s", authorProfileString) return "", err } From 5745a9b3c4bb5f1349af95857f939212f56a9ac0 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 5 Jun 2024 22:07:06 +0300 Subject: [PATCH 15/22] fixed-redis-intfix --- server/memorystore/providers/redis/store.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index a2b7c0e..87a32df 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -247,7 +247,8 @@ func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { return "", err } - authorId, ok := authorProfileMap["id"].(int) + authorId, ok := authorProfileMap["id"].(float64) + authorId = int(authorId) if !ok { fmt.Println("Ошибка: id не найден или неверного типа") return "", errors.New("id not found or is of incorrect type") From 7d5d31692f036fae66d49a2513b1befd1061c7e3 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 5 Jun 2024 22:10:43 +0300 Subject: [PATCH 16/22] fixed-redis-intfix2 --- server/memorystore/providers/redis/store.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index 87a32df..dcf384c 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -246,13 +246,12 @@ func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { if err != nil { return "", err } - - authorId, ok := authorProfileMap["id"].(float64) - authorId = int(authorId) - if !ok { - fmt.Println("Ошибка: id не найден или неверного типа") - return "", errors.New("id not found or is of incorrect type") - } + + authorIdFloat, ok := authorProfileMap["id"].(float64) + if !ok { + return "", errors.New("id not found or is of incorrect type") + } + authorId := int(authorIdFloat) // Начинаем сбор данных в общий JSON combinedData := map[string]interface{}{ From 86453d483ee23a40cb6de59346e77733337057f7 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 5 Jun 2024 22:15:03 +0300 Subject: [PATCH 17/22] =?UTF-8?q?fixed-redis-intfix2-=D0=B2=D1=83=D0=B8?= =?UTF-8?q?=D0=B3=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/memorystore/providers/redis/store.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index dcf384c..11262ea 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -235,8 +235,8 @@ func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { rkey := fmt.Sprintf("author:user:%s", userId) authorProfileString, err := c.store.Get(c.ctx, rkey).Result() if err != nil { - fmt.Println("redis GET: %s", rkey) - fmt.Println("%s", authorProfileString) + fmt.Println("redis GET:", rkey) + fmt.Println(authorProfileString) return "", err } From 800fc4f8d875061e16622d486ae66f68389cda0d Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 5 Jun 2024 22:17:18 +0300 Subject: [PATCH 18/22] fixed-redis-intfix4 --- server/memorystore/providers/redis/store.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index 11262ea..10fd46f 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -3,6 +3,7 @@ package redis import ( "fmt" "strconv" + "strings" "time" "errors" "encoding/json" @@ -232,7 +233,7 @@ type AuthorProfile struct { // and assigns the JSON string to the provided user's ID. func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { // Получаем профиль автора из Redis - rkey := fmt.Sprintf("author:user:%s", userId) + rkey := fmt.Sprintf("author:user:%s", strings.TrimSpace(userId)) authorProfileString, err := c.store.Get(c.ctx, rkey).Result() if err != nil { fmt.Println("redis GET:", rkey) From bfa192d21e08557f73916452b162283714790673 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 5 Jun 2024 23:20:37 +0300 Subject: [PATCH 19/22] log-author-id --- server/memorystore/providers/redis/store.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index 10fd46f..a3d8fec 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -253,6 +253,7 @@ func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { return "", errors.New("id not found or is of incorrect type") } authorId := int(authorIdFloat) + fmt.Println("author id:", authorId) // Начинаем сбор данных в общий JSON combinedData := map[string]interface{}{ From e9f54a74f0bfa984265c9e1120221e26a89ed3a3 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 5 Jun 2024 23:40:09 +0300 Subject: [PATCH 20/22] get-id --- server/memorystore/providers/redis/store.go | 29 +++++++++++---------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index a3d8fec..c22335a 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -3,9 +3,7 @@ package redis import ( "fmt" "strconv" - "strings" "time" - "errors" "encoding/json" "github.com/authorizerdev/authorizer/server/constants" @@ -232,12 +230,22 @@ type AuthorProfile struct { // 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) { - // Получаем профиль автора из Redis - rkey := fmt.Sprintf("author:user:%s", strings.TrimSpace(userId)) - authorProfileString, err := c.store.Get(c.ctx, rkey).Result() + // Получаем ID автора из Redis + authorIdString, err := c.store.Get(c.ctx, fmt.Sprintf("author:user:%s", userId)).Result() + if err != nil { + return "", err + } + + // Преобразуем ID автора из строки в int + var authorId int + err = json.Unmarshal([]byte(authorIdString), &authorId) + if err != nil { + return "", err + } + + // Получаем профиль автора из Redis + authorProfileString, err := c.store.Get(c.ctx, fmt.Sprintf("author:id:%d", authorId)).Result() if err != nil { - fmt.Println("redis GET:", rkey) - fmt.Println(authorProfileString) return "", err } @@ -247,13 +255,6 @@ func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { if err != nil { return "", err } - - authorIdFloat, ok := authorProfileMap["id"].(float64) - if !ok { - return "", errors.New("id not found or is of incorrect type") - } - authorId := int(authorIdFloat) - fmt.Println("author id:", authorId) // Начинаем сбор данных в общий JSON combinedData := map[string]interface{}{ From 55121656a8b36c7511db5ac0273b6edc55a6b441 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 5 Jun 2024 23:47:41 +0300 Subject: [PATCH 21/22] get-id --- server/memorystore/providers/redis/store.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index c22335a..6609673 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -237,11 +237,12 @@ func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { } // Преобразуем ID автора из строки в int - var authorId int - err = json.Unmarshal([]byte(authorIdString), &authorId) + var authorIdFloat float64 + err = json.Unmarshal([]byte(authorIdString), &authorIdFloat) if err != nil { return "", err } + authorId := int(authorIdFloat) // Получаем профиль автора из Redis authorProfileString, err := c.store.Get(c.ctx, fmt.Sprintf("author:id:%d", authorId)).Result() From 48e1dbf8aa8b502e5e037e9d97dc939c1c298f77 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 6 Jun 2024 07:51:45 +0300 Subject: [PATCH 22/22] get-id-debug --- server/memorystore/providers/redis/store.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index 6609673..2129956 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -231,10 +231,13 @@ type AuthorProfile struct { // and assigns the JSON string to the provided user's ID. func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { // Получаем ID автора из Redis - authorIdString, err := c.store.Get(c.ctx, fmt.Sprintf("author:user:%s", userId)).Result() + rkey := fmt.Sprintf("author:user:%s", userId) + fmt.Println("get redis cached by key:", rkey) + authorIdString, err := c.store.Get(c.ctx, rkey).Result() if err != nil { return "", err } + fmt.Println("redis found string value:", authorIdString) // Преобразуем ID автора из строки в int var authorIdFloat float64 @@ -243,6 +246,7 @@ func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { return "", err } authorId := int(authorIdFloat) + fmt.Println("recognized author id: ", authorId) // Получаем профиль автора из Redis authorProfileString, err := c.store.Get(c.ctx, fmt.Sprintf("author:id:%d", authorId)).Result()