Skip to content

Commit

Permalink
Merge pull request #2337 from opengovern/fix-tasks
Browse files Browse the repository at this point in the history
fix: preload query in fetching views in db
  • Loading branch information
artaasadi authored Dec 29, 2024
2 parents 8aa3cf1 + e9bad08 commit aea4d4b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/cloudql/sdk/extra/view-sync/view_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package view_sync

import (
"context"
"gorm.io/gorm/clause"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -132,7 +133,7 @@ func (v *ViewSync) updateViewsInDatabase(ctx context.Context, selfClient *steamp

var queryViews []models.QueryView

err := metadataClient.DB().Model(&models.QueryView{}).Find(&queryViews).Error
err := metadataClient.DB().Model(&models.QueryView{}).Preload(clause.Associations).Preload("Query.Parameters").Find(&queryViews).Error
if err != nil {
v.logger.Error("Error fetching query views from metadata", zap.Error(err))
v.logger.Sync()
Expand Down Expand Up @@ -176,6 +177,11 @@ initLoop:
continue
}

if view.Query == nil || view.Query.QueryToExecute == "" {
v.logger.Error("Error fetching view from database", zap.String("view", view.ID))
continue
}

query := "CREATE MATERIALIZED VIEW IF NOT EXISTS " + view.ID + " AS " + view.Query.QueryToExecute
_, err = selfClient.GetConnection().Exec(ctx, query)
if err != nil && strings.Contains(err.Error(), "SQLSTATE 42P01") {
Expand Down

0 comments on commit aea4d4b

Please sign in to comment.