From da161859f948b51163c6d277ec7d790b8a7fbc20 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 10 Jan 2024 01:44:58 +0000 Subject: [PATCH 1/4] chore(deps): update golang docker tag to v1.21.6 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 70f3b428..e1f8a708 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21.4-alpine AS base +FROM golang:1.21.6-alpine AS base WORKDIR /app # builder From e0a0218ed035030158efae9b10b02d765909a58a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 19 Dec 2023 04:53:32 +0000 Subject: [PATCH 2/4] fix(deps): update module golang.org/x/mod to v0.14.0 --- go.mod | 4 ++-- go.sum | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index a3c5219e..0042c8ec 100644 --- a/go.mod +++ b/go.mod @@ -60,7 +60,7 @@ require ( go.opentelemetry.io/otel/sdk v1.16.0 go.uber.org/fx v1.19.2 golang.org/x/exp v0.0.0-20220823124025-807a23277127 - golang.org/x/mod v0.9.0 + golang.org/x/mod v0.14.0 golang.org/x/sync v0.5.0 golang.org/x/text v0.14.0 google.golang.org/protobuf v1.30.0 @@ -162,7 +162,7 @@ require ( golang.org/x/crypto v0.14.0 // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/sys v0.13.0 // indirect - golang.org/x/tools v0.7.0 // indirect + golang.org/x/tools v0.13.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect mellium.im/sasl v0.3.1 // indirect ) diff --git a/go.sum b/go.sum index c1d3ef63..727664e9 100644 --- a/go.sum +++ b/go.sum @@ -636,6 +636,8 @@ golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= +golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -839,6 +841,8 @@ golang.org/x/tools v0.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= +golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From b6ac0a59d0bd59adf0776963bc919d92100ab41d Mon Sep 17 00:00:00 2001 From: GalvinGao Date: Wed, 15 May 2024 00:37:32 +0900 Subject: [PATCH 3/4] feat: add cache for account existence --- internal/model/cache/caches.go | 3 +++ internal/repo/account.go | 15 ++++++++++++++- internal/repo/drop_report_extra.go | 7 ++++--- internal/util/reportverifs/verify_md5.go | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/internal/model/cache/caches.go b/internal/model/cache/caches.go index e2d008ee..df97701b 100644 --- a/internal/model/cache/caches.go +++ b/internal/model/cache/caches.go @@ -19,6 +19,7 @@ type Flusher func() error var ( AccountByID *cache.Set[model.Account] AccountByPenguinID *cache.Set[model.Account] + AccountExistence *cache.Set[int] ItemDropSetByStageIDAndRangeID *cache.Set[[]int] ItemDropSetByStageIdAndTimeRange *cache.Set[[]int] @@ -116,9 +117,11 @@ func initializeCaches() { // account AccountByID = cache.NewSet[model.Account]("account#accountId") AccountByPenguinID = cache.NewSet[model.Account]("account#penguinId") + AccountExistence = cache.NewSet[int]("accountExistence#accountId") SetMap["account#accountId"] = AccountByID.Flush SetMap["account#penguinId"] = AccountByPenguinID.Flush + SetMap["accountExistence#accountId"] = AccountExistence.Flush // drop_info ItemDropSetByStageIDAndRangeID = cache.NewSet[[]int]("itemDropSet#server|stageId|rangeId") diff --git a/internal/repo/account.go b/internal/repo/account.go index c235aaad..d0d1fc66 100644 --- a/internal/repo/account.go +++ b/internal/repo/account.go @@ -2,12 +2,14 @@ package repo import ( "context" + "strconv" "time" "github.com/rs/zerolog/log" "github.com/uptrace/bun" "exusiai.dev/backend-next/internal/model" + "exusiai.dev/backend-next/internal/model/cache" "exusiai.dev/backend-next/internal/pkg/pgerr" "exusiai.dev/backend-next/internal/pkg/pgid" "exusiai.dev/backend-next/internal/repo/selector" @@ -74,6 +76,11 @@ func (r *Account) GetAccountByPenguinId(ctx context.Context, penguinId string) ( } func (r *Account) IsAccountExistWithId(ctx context.Context, accountId int) bool { + var exist int + err := cache.AccountExistence.Get(strconv.Itoa(accountId), &exist) + if err == nil { + return exist == 1 + } account, err := r.sel.SelectOne(ctx, func(q *bun.SelectQuery) *bun.SelectQuery { return q.Column("account_id").Where("account_id = ?", accountId) }) @@ -81,5 +88,11 @@ func (r *Account) IsAccountExistWithId(ctx context.Context, accountId int) bool return false } - return account != nil + exists := account != nil + + if exists { + cache.AccountExistence.Set(strconv.Itoa(account.AccountID), 1, time.Hour*24) + } + + return exists } diff --git a/internal/repo/drop_report_extra.go b/internal/repo/drop_report_extra.go index 6ee64493..f3950647 100644 --- a/internal/repo/drop_report_extra.go +++ b/internal/repo/drop_report_extra.go @@ -73,15 +73,16 @@ func (c *DropReportExtra) DeleteDropReportExtrasForArchive(ctx context.Context, func (c *DropReportExtra) IsDropReportExtraMD5Exist(ctx context.Context, md5 string) bool { var dropReportExtra model.DropReportExtra - count, err := c.db.NewSelect(). + err := c.db.NewSelect(). Model(&dropReportExtra). Where("md5 = ?", md5). - Count(ctx) + Limit(1). + Scan(ctx) if err != nil { return false } - return count > 0 + return true } func (r *DropReportExtra) CreateDropReportExtra(ctx context.Context, tx bun.Tx, report *model.DropReportExtra) error { diff --git a/internal/util/reportverifs/verify_md5.go b/internal/util/reportverifs/verify_md5.go index 1f28ff16..df068397 100644 --- a/internal/util/reportverifs/verify_md5.go +++ b/internal/util/reportverifs/verify_md5.go @@ -3,11 +3,11 @@ package reportverifs import ( "context" + "exusiai.dev/gommon/constant" "github.com/pkg/errors" "exusiai.dev/backend-next/internal/model/types" "exusiai.dev/backend-next/internal/repo" - "exusiai.dev/gommon/constant" ) var ErrMD5Conflict = errors.New("report with specified md5 has already existed") From 22a49f1b44b9f7a2155d7b194815c9ce16214fd0 Mon Sep 17 00:00:00 2001 From: GalvinGao Date: Wed, 15 May 2024 00:41:34 +0900 Subject: [PATCH 4/4] fix: remove properties --- internal/model/cache/caches.go | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/internal/model/cache/caches.go b/internal/model/cache/caches.go index df97701b..9e3b70db 100644 --- a/internal/model/cache/caches.go +++ b/internal/model/cache/caches.go @@ -1,7 +1,6 @@ package cache import ( - "context" "sync" "time" @@ -11,7 +10,6 @@ import ( "exusiai.dev/backend-next/internal/model" modelv2 "exusiai.dev/backend-next/internal/model/v2" "exusiai.dev/backend-next/internal/pkg/cache" - "exusiai.dev/backend-next/internal/repo" ) type Flusher func() error @@ -74,18 +72,15 @@ var ( LastModifiedTime *cache.Set[time.Time] - Properties map[string]string - once sync.Once SetMap map[string]Flusher SingularFlusherMap map[string]Flusher ) -func Initialize(propertyRepo *repo.Property) { +func Initialize() { once.Do(func() { initializeCaches() - populateProperties(propertyRepo) }) } @@ -242,15 +237,3 @@ func initializeCaches() { SetMap["lastModifiedTime#key"] = LastModifiedTime.Flush } - -func populateProperties(repo *repo.Property) { - Properties = make(map[string]string) - properties, err := repo.GetProperties(context.Background()) - if err != nil { - panic(err) - } - - for _, property := range properties { - Properties[property.Key] = property.Value - } -}