-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(backend): optimize database query for deployment with latest sta…
…tus (#473) Signed-off-by: Jakob Steiner <[email protected]>
- Loading branch information
Showing
4 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
internalctx "github.com/glasskube/distr/internal/context" | ||
"github.com/glasskube/distr/internal/db" | ||
"github.com/glasskube/distr/internal/svc" | ||
"github.com/glasskube/distr/internal/types" | ||
"github.com/glasskube/distr/internal/util" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
registry := util.Require(svc.NewDefault(ctx)) | ||
defer func() { _ = registry.Shutdown() }() | ||
ctx = internalctx.WithDb(ctx, registry.GetDbPool()) | ||
|
||
revisionID := "68297e49-b17b-4d32-8111-f8ee678f73da" | ||
statusCount := 500000 | ||
statusInterval := 5 * time.Second | ||
|
||
now := time.Now().UTC() | ||
createdAt := now.Add(time.Duration(statusCount) * -statusInterval) | ||
var ds []types.DeploymentRevisionStatus | ||
for createdAt.Before(now) { | ||
ds = append(ds, types.DeploymentRevisionStatus{CreatedAt: createdAt, Message: "demo status"}) | ||
createdAt = createdAt.Add(statusInterval) | ||
} | ||
util.Must(db.BulkCreateDeploymentRevisionStatusWithCreatedAt(ctx, revisionID, ds)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
internal/migrations/sql/14_deployment_revision_created_at_index.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP INDEX DeploymentRevisionStatus_created_at; |
1 change: 1 addition & 0 deletions
1
internal/migrations/sql/14_deployment_revision_created_at_index.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE INDEX DeploymentRevisionStatus_created_at ON DeploymentRevisionStatus (deployment_revision_id, created_at DESC); |