From 31f1696fd64eebfe3f92c9efd437a797692811b1 Mon Sep 17 00:00:00 2001 From: Jonada Hoxha Date: Sat, 1 Jun 2024 23:32:57 +0200 Subject: [PATCH] Update `warmup` function to optimize `container log` retrieval --- pkg/schema/v1/container.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/schema/v1/container.go b/pkg/schema/v1/container.go index 6045dfd1..d6888561 100644 --- a/pkg/schema/v1/container.go +++ b/pkg/schema/v1/container.go @@ -289,9 +289,13 @@ func SyncContainers(ctx context.Context, db *database.Database, g *errgroup.Grou func warmup(ctx context.Context, db *database.Database) error { g, ctx := errgroup.WithContext(ctx) + query := `SELECT cl.* FROM container_log cl INNER JOIN (SELECT container_uuid, pod_uuid, MAX(last_update) as last_update + FROM container_log GROUP BY container_uuid) max_cl ON cl.container_uuid = max_cl.container_uuid AND cl.pod_uuid = max_cl.pod_uuid + AND cl.last_update = max_cl.last_update` + entities, errs := db.YieldAll(ctx, func() (interface{}, error) { return &ContainerLog{}, nil - }, db.BuildSelectStmt(ContainerLog{}, ContainerLog{})) + }, query) com.ErrgroupReceive(ctx, g, errs) g.Go(func() error {