Skip to content

Commit

Permalink
fix: get series limit error
Browse files Browse the repository at this point in the history
  • Loading branch information
minoic committed Apr 28, 2024
1 parent efd50ba commit ccceb4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion common/cache/user_entity_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"
)

const UserEntitiesKey = "UserEntities_"
const UserEntitiesKey = "USER_ENTITIES_"

func GetUserEntities(ctx context.Context, userId primitive.ObjectID) ([]models.Application, error) {
ret, err := storage.QuickRCSearch[[]models.Application](ctx, UserEntitiesKey+UserEntitiesKey+userId.Hex(), func() ([]models.Application, error) {
Expand Down
16 changes: 10 additions & 6 deletions modules/backend/app/mobile/entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,19 +492,19 @@ func (h handler) GetSeries(ctx context.Context, id *EntityID) (*EntitySeries, er
ret := &EntitySeries{
ID: id.GetID(),
}
series := map[string]interface{}{}
series := map[string][]interface{}{}
query, err := storage.QueryInfluxDB.Query(ctx,
fmt.Sprintf(`
import "types"
import "strings"
from(bucket: "backend")
|> range(start: -10m)
|> range(start: -1h)
|> filter(fn: (r) => r["_measurement"] == "%s")
|> filter(fn: (r) => r["id"] == "%s")
|> filter(fn: (r) => types.isNumeric(v: r["_value"]))
|> filter(fn: (r) => not strings.hasPrefix(v: r["_field"], prefix: "c_"))
|> sort(columns: ["_time"], desc: true)
|> limit(n:60)
|> limit(n:65)
|> sort(columns: ["_time"], desc: false)`,
id.GetScheme(),
id.GetID()))
Expand All @@ -514,11 +514,15 @@ from(bucket: "backend")
}
for query.Next() {
if series[query.Record().Field()] == nil {
series[query.Record().Field()] = []interface{}{}
series[query.Record().Field()] = make([]interface{}, 0, 70)
}
series[query.Record().Field()] = append(series[query.Record().Field()].([]interface{}), query.Record().Value())
series[query.Record().Field()] = append(series[query.Record().Field()], query.Record().Value())
}
ret.Series, err = structpb.NewStruct(series)
s := map[string]interface{}{}
for k, v := range series {
s[k] = v
}
ret.Series, err = structpb.NewStruct(s)
if err != nil {
glgf.Error(err)
return ret, status.Error(codes.Internal, err.Error())
Expand Down

0 comments on commit ccceb4d

Please sign in to comment.