feat(backend): fixed issue in start request

This commit is contained in:
Alexander 2024-01-26 14:25:44 +01:00
parent 354f071fb0
commit df2ee71bbb
3 changed files with 11 additions and 6 deletions

View file

@ -168,12 +168,11 @@ func (e *Router) startSessionHandlerWeb(w http.ResponseWriter, r *http.Request)
dice := byte(rand.Intn(100)) // [0, 100)
// Use condition rate if it's set
if req.Condition != "" {
rate, err := e.services.Conditions.GetRate(p.ProjectID, req.Condition)
rate, err := e.services.Conditions.GetRate(p.ProjectID, req.Condition, int(p.SampleRate))
if err != nil {
log.Printf("can't get condition rate: %s", err)
} else {
log.Printf("condition rate: %d", rate)
p.SampleRate = byte(rate) // why byte?
p.SampleRate = byte(rate)
}
} else {
log.Printf("project sample rate: %d", p.SampleRate)

View file

@ -4,10 +4,16 @@ import (
"openreplay/backend/pkg/db/postgres/pool"
)
type Conditions interface{}
type Conditions interface {
GetRate(projectID uint32, condition string, def int) (int, error)
}
type conditionsImpl struct{}
func (c *conditionsImpl) GetRate(projectID uint32, condition string, def int) (int, error) {
return def, nil
}
func New(db pool.Pool) Conditions {
return &conditionsImpl{}
}

View file

@ -8,7 +8,7 @@ import (
type Conditions interface {
Get(projectID uint32) (*Response, error)
GetRate(projectID uint32, condition string) (int, error)
GetRate(projectID uint32, condition string, def int) (int, error)
}
type conditionsImpl struct {
@ -108,7 +108,7 @@ func (c *conditionsImpl) Get(projectID uint32) (*Response, error) {
return &Response{Conditions: conditions}, err
}
func (c *conditionsImpl) GetRate(projectID uint32, condition string) (int, error) {
func (c *conditionsImpl) GetRate(projectID uint32, condition string, def int) (int, error) {
proj, ok := c.cache[projectID]
if ok {
rate, ok := proj[condition]