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 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= diff --git a/internal/model/cache/caches.go b/internal/model/cache/caches.go index e2d008ee..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 @@ -19,6 +17,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] @@ -73,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) }) } @@ -116,9 +112,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") @@ -239,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 - } -} 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")