limit the number of orders someone can add to a query (3)

This commit is contained in:
Dawid Wysokiński 2021-05-05 20:15:51 +02:00
parent 6a44193f31
commit 7f59bcf2cd
26 changed files with 64 additions and 0 deletions

View File

@ -2,4 +2,5 @@ package dailyplayerstats
const (
FetchLimit = 1000
MaxOrders = 3
)

View File

@ -23,5 +23,8 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg dailyplayerstats.FetchConfi
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > dailyplayerstats.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = dailyplayerstats.FetchLimit
}
if len(cfg.Sort) > dailyplayerstats.MaxOrders {
cfg.Sort = cfg.Sort[0:dailyplayerstats.MaxOrders]
}
return ucase.repo.Fetch(ctx, cfg)
}

View File

@ -2,4 +2,5 @@ package dailytribestats
const (
FetchLimit = 1000
MaxOrders = 3
)

View File

@ -23,5 +23,8 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg dailytribestats.FetchConfig
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > dailytribestats.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = dailytribestats.FetchLimit
}
if len(cfg.Sort) > dailytribestats.MaxOrders {
cfg.Sort = cfg.Sort[0:dailytribestats.MaxOrders]
}
return ucase.repo.Fetch(ctx, cfg)
}

View File

@ -2,4 +2,5 @@ package ennoblement
const (
FetchLimit = 200
MaxOrders = 3
)

View File

@ -23,5 +23,8 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg ennoblement.FetchConfig) ([
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > ennoblement.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = ennoblement.FetchLimit
}
if len(cfg.Sort) > ennoblement.MaxOrders {
cfg.Sort = cfg.Sort[0:ennoblement.MaxOrders]
}
return ucase.repo.Fetch(ctx, cfg)
}

View File

@ -2,4 +2,5 @@ package player
const (
FetchLimit = 200
MaxOrders = 3
)

View File

@ -25,6 +25,9 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg player.FetchConfig) ([]*twm
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > player.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = player.FetchLimit
}
if len(cfg.Sort) > player.MaxOrders {
cfg.Sort = cfg.Sort[0:player.MaxOrders]
}
return ucase.repo.Fetch(ctx, cfg)
}
@ -57,5 +60,8 @@ func (ucase *usecase) SearchPlayer(ctx context.Context, cfg player.SearchPlayerC
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > player.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = player.FetchLimit
}
if len(cfg.Sort) > player.MaxOrders {
cfg.Sort = cfg.Sort[0:player.MaxOrders]
}
return ucase.repo.SearchPlayer(ctx, cfg)
}

View File

@ -2,4 +2,5 @@ package playerhistory
const (
FetchLimit = 100
MaxOrders = 3
)

View File

@ -23,5 +23,8 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg playerhistory.FetchConfig)
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > playerhistory.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = playerhistory.FetchLimit
}
if len(cfg.Sort) > playerhistory.MaxOrders {
cfg.Sort = cfg.Sort[0:playerhistory.MaxOrders]
}
return ucase.repo.Fetch(ctx, cfg)
}

View File

@ -2,4 +2,5 @@ package server
const (
FetchLimit = 100
MaxOrders = 3
)

View File

@ -24,6 +24,9 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg server.FetchConfig) ([]*twm
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > server.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = server.FetchLimit
}
if len(cfg.Sort) > server.MaxOrders {
cfg.Sort = cfg.Sort[0:server.MaxOrders]
}
return ucase.repo.Fetch(ctx, cfg)
}

5
servermap/constants.go Normal file
View File

@ -0,0 +1,5 @@
package servermap
const (
MaxMarkers = 100
)

View File

@ -210,7 +210,11 @@ func toMarkers(params []string) (map[string][]int, []int, error) {
idsByColor := make(map[string][]int)
var ids []int
cache := make(map[int]bool)
count := 0
for _, param := range params {
if count >= servermap.MaxMarkers {
break
}
//id,#color
id, color, err := toMarker(param)
if err != nil {
@ -222,6 +226,7 @@ func toMarkers(params []string) (map[string][]int, []int, error) {
ids = append(ids, id)
cache[id] = true
idsByColor[color] = append(idsByColor[color], id)
count++
}
return idsByColor, ids, nil
}

View File

@ -2,4 +2,5 @@ package serverstats
const (
FetchLimit = 60
MaxOrders = 3
)

View File

@ -23,5 +23,8 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg serverstats.FetchConfig) ([
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > serverstats.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = serverstats.FetchLimit
}
if len(cfg.Sort) > serverstats.MaxOrders {
cfg.Sort = cfg.Sort[0:serverstats.MaxOrders]
}
return ucase.repo.Fetch(ctx, cfg)
}

View File

@ -2,4 +2,5 @@ package tribe
const (
FetchLimit = 200
MaxOrders = 3
)

View File

@ -25,6 +25,9 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg tribe.FetchConfig) ([]*twmo
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > tribe.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = tribe.FetchLimit
}
if len(cfg.Sort) > tribe.MaxOrders {
cfg.Sort = cfg.Sort[0:tribe.MaxOrders]
}
return ucase.repo.Fetch(ctx, cfg)
}
@ -57,5 +60,8 @@ func (ucase *usecase) SearchTribe(ctx context.Context, cfg tribe.SearchTribeConf
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > tribe.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = tribe.FetchLimit
}
if len(cfg.Sort) > tribe.MaxOrders {
cfg.Sort = cfg.Sort[0:tribe.MaxOrders]
}
return ucase.repo.SearchTribe(ctx, cfg)
}

View File

@ -2,4 +2,5 @@ package tribechange
const (
FetchLimit = 100
MaxOrders = 3
)

View File

@ -23,5 +23,8 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg tribechange.FetchConfig) ([
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > tribechange.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = tribechange.FetchLimit
}
if len(cfg.Sort) > tribechange.MaxOrders {
cfg.Sort = cfg.Sort[0:tribechange.MaxOrders]
}
return ucase.repo.Fetch(ctx, cfg)
}

View File

@ -2,4 +2,5 @@ package tribehistory
const (
FetchLimit = 100
MaxOrders = 3
)

View File

@ -23,5 +23,8 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg tribehistory.FetchConfig) (
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > tribehistory.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = tribehistory.FetchLimit
}
if len(cfg.Sort) > tribehistory.MaxOrders {
cfg.Sort = cfg.Sort[0:tribehistory.MaxOrders]
}
return ucase.repo.Fetch(ctx, cfg)
}

View File

@ -2,4 +2,5 @@ package version
const (
FetchLimit = 30
MaxOrders = 3
)

View File

@ -26,6 +26,9 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg version.FetchConfig) ([]*tw
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > version.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = version.FetchLimit
}
if len(cfg.Sort) > version.MaxOrders {
cfg.Sort = cfg.Sort[0:version.MaxOrders]
}
return ucase.repo.Fetch(ctx, cfg)
}

View File

@ -2,4 +2,5 @@ package village
const (
FetchLimit = 1000
MaxOrders = 3
)

View File

@ -24,6 +24,9 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg village.FetchConfig) ([]*tw
if !middleware.CanExceedLimit(ctx) && (cfg.Limit > village.FetchLimit || cfg.Limit <= 0) {
cfg.Limit = village.FetchLimit
}
if len(cfg.Sort) > village.MaxOrders {
cfg.Sort = cfg.Sort[0:village.MaxOrders]
}
return ucase.repo.Fetch(ctx, cfg)
}