Skip to content

Commit

Permalink
fix: preload query in fetching views in db
Browse files Browse the repository at this point in the history
  • Loading branch information
artaasadi committed Dec 29, 2024
1 parent 14a46fb commit e9bad08
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 e9bad08

Please sign in to comment.