Skip to content

Commit

Permalink
Merge pull request #525 from penguin-statistics/dev
Browse files Browse the repository at this point in the history
Release v3.14.12
  • Loading branch information
AlvISsReimu committed May 15, 2024
2 parents 570c91f + 22a49f1 commit 606e21c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21.4-alpine AS base
FROM golang:1.21.6-alpine AS base
WORKDIR /app

# builder
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
22 changes: 4 additions & 18 deletions internal/model/cache/caches.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cache

import (
"context"
"sync"
"time"

Expand All @@ -11,14 +10,14 @@ 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

var (
AccountByID *cache.Set[model.Account]
AccountByPenguinID *cache.Set[model.Account]
AccountExistence *cache.Set[int]

ItemDropSetByStageIDAndRangeID *cache.Set[[]int]
ItemDropSetByStageIdAndTimeRange *cache.Set[[]int]
Expand Down Expand Up @@ -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)
})
}

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
}
15 changes: 14 additions & 1 deletion internal/repo/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -74,12 +76,23 @@ 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)
})
if err != nil {
return false
}

return account != nil
exists := account != nil

if exists {
cache.AccountExistence.Set(strconv.Itoa(account.AccountID), 1, time.Hour*24)
}

return exists
}
7 changes: 4 additions & 3 deletions internal/repo/drop_report_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/util/reportverifs/verify_md5.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 606e21c

Please sign in to comment.