Skip to content

Commit

Permalink
chore: fix pageToken bug (#520)
Browse files Browse the repository at this point in the history
Because

- The `pageToken` is not correctly encoded due to the refactor to
camelCase.

This commit

- Fixes the `pageToken` bug.
  • Loading branch information
donch1989 committed Jun 18, 2024
1 parent 0809371 commit eb22b30
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ dev: ## Run dev container
@docker run -d --rm \
-v $(PWD):/${SERVICE_NAME} \
-p ${SERVICE_PORT}:${SERVICE_PORT} \
-v $(PWD)/../go.work:/go.work \
-v $(PWD)/../go.work.sum:/go.work.sum \
-v $(PWD)/../component:/component \
-v $(PWD)/../pipeline-backend-cloud:/pipeline-backend-cloud \
-v $(PWD)/../protogengo:/protogengo \
--network instill-network \
--name ${SERVICE_NAME} \
instill/${SERVICE_NAME}:dev >/dev/null 2>&1
Expand All @@ -46,6 +51,7 @@ top: ## Display all running service processes
build: ## Build dev docker image
@docker build \
--build-arg SERVICE_NAME=${SERVICE_NAME} \
--build-arg GOLANG_VERSION=${GOLANG_VERSION} \
--build-arg K6_VERSION=${K6_VERSION} \
-f Dockerfile.dev -t instill/${SERVICE_NAME}:dev .

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1
github.com/iancoleman/strcase v0.3.0
github.com/influxdata/influxdb-client-go/v2 v2.12.3
github.com/instill-ai/component v0.19.1-beta.0.20240618054722-d3de43ea6b74
github.com/instill-ai/component v0.19.1-beta.0.20240618161039-c7059d77ab27
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240531114421-d7be5dd350e5
github.com/instill-ai/usage-client v0.2.4-alpha.0.20240123081026-6c78d9a5197a
github.com/instill-ai/x v0.4.0-alpha
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1183,8 +1183,8 @@ github.com/influxdata/influxdb-client-go/v2 v2.12.3 h1:28nRlNMRIV4QbtIUvxhWqaxn0
github.com/influxdata/influxdb-client-go/v2 v2.12.3/go.mod h1:IrrLUbCjjfkmRuaCiGQg4m2GbkaeJDcuWoxiWdQEbA0=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/instill-ai/component v0.19.1-beta.0.20240618054722-d3de43ea6b74 h1:dVcdDrInqkZFZtAB57GnIY+2xe3p4SVWAje24gdU+HE=
github.com/instill-ai/component v0.19.1-beta.0.20240618054722-d3de43ea6b74/go.mod h1:4w/nWenyxLrGVUmAZ1Y+yWFa+IjXEiFTyay63HkAXZ4=
github.com/instill-ai/component v0.19.1-beta.0.20240618161039-c7059d77ab27 h1:w1Y2Zm2AxZ4e87LSv2xDYqMYqEW/hBJyKfHsF42joQA=
github.com/instill-ai/component v0.19.1-beta.0.20240618161039-c7059d77ab27/go.mod h1:4w/nWenyxLrGVUmAZ1Y+yWFa+IjXEiFTyay63HkAXZ4=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240531114421-d7be5dd350e5 h1:lAOZK6B63kIC7dRFEeILzQp4dEb14ngYRnD03k8LkOw=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240531114421-d7be5dd350e5/go.mod h1:2blmpUwiTwxIDnrjIqT6FhR5ewshZZF554wzjXFvKpQ=
github.com/instill-ai/usage-client v0.2.4-alpha.0.20240123081026-6c78d9a5197a h1:gmy8BcCFDZQan40c/D3f62DwTYtlCwi0VrSax+pKffw=
Expand Down
22 changes: 12 additions & 10 deletions pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,22 @@ func (r *repository) listPipelines(ctx context.Context, where string, whereArgs

for _, o := range order.Fields {

if v, ok := tokens[o.Path]; ok {
switch o.Path {
p := strcase.ToSnake(o.Path)
if v, ok := tokens[p]; ok {

switch p {
case "create_time", "update_time":
// Add "pipeline." prefix to prevent ambiguous since tag table also has the two columns.
if o.Desc {
queryBuilder = queryBuilder.Where("pipeline."+o.Path+" < ?::timestamp", v)
queryBuilder = queryBuilder.Where("pipeline."+p+" < ?::timestamp", v)
} else {
queryBuilder = queryBuilder.Where("pipeline."+o.Path+" > ?::timestamp", v)
queryBuilder = queryBuilder.Where("pipeline."+p+" > ?::timestamp", v)
}
default:
if o.Desc {
queryBuilder = queryBuilder.Where(o.Path+" < ?", v)
queryBuilder = queryBuilder.Where(p+" < ?", v)
} else {
queryBuilder = queryBuilder.Where(o.Path+" > ?", v)
queryBuilder = queryBuilder.Where(p+" > ?", v)
}
}

Expand Down Expand Up @@ -290,13 +292,13 @@ func (r *repository) listPipelines(ctx context.Context, where string, whereArgs
for _, field := range order.Fields {
orderString := strcase.ToSnake(field.Path) + transformBoolToDescString(!field.Desc)
lastItemQueryBuilder.Order(orderString)
switch strcase.ToSnake(field.Path) {
switch p := strcase.ToSnake(field.Path); p {
case "id":
tokens[field.Path] = lastID
tokens[p] = lastID
case "create_time":
tokens[field.Path] = lastCreateTime.Format(time.RFC3339Nano)
tokens[p] = lastCreateTime.Format(time.RFC3339Nano)
case "update_time":
tokens[field.Path] = lastUpdateTime.Format(time.RFC3339Nano)
tokens[p] = lastUpdateTime.Format(time.RFC3339Nano)
}

}
Expand Down

0 comments on commit eb22b30

Please sign in to comment.