Skip to content

Commit

Permalink
Fix filewatching to create prepared statements for new sql files. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidaguerre committed Sep 28, 2021
1 parent 6aeaaed commit 5994113
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions db/db_common/prepared_statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ func CreatePreparedStatements(ctx context.Context, resourceMaps *modconfig.Works
}

// UpdatePreparedStatements first attempts to deallocate all prepared statements in workspace, then recreates them
func UpdatePreparedStatements(ctx context.Context, resourceMaps *modconfig.WorkspaceResourceMaps, client Client) error {
func UpdatePreparedStatements(ctx context.Context, prevResourceMaps, currentResourceMaps *modconfig.WorkspaceResourceMaps, client Client) error {
log.Printf("[TRACE] UpdatePreparedStatements")

utils.LogTime("db.UpdatePreparedStatements start")
defer utils.LogTime("db.UpdatePreparedStatements end")

var sql []string
for name, query := range resourceMaps.QueryMap {
for name, query := range prevResourceMaps.QueryMap {
// query map contains long and short names for queries - avoid dupes
if !strings.HasPrefix(name, "query.") {
continue
}
sql = append(sql, fmt.Sprintf("DEALLOCATE %s;", query.PreparedStatementName()))
}
for name, control := range resourceMaps.ControlMap {
for name, control := range prevResourceMaps.ControlMap {
// query map contains long and short names for controls - avoid dupes
if !strings.HasPrefix(name, "control.") {
continue
Expand All @@ -95,6 +95,6 @@ func UpdatePreparedStatements(ctx context.Context, resourceMaps *modconfig.Works
}

// now recreate them
return CreatePreparedStatements(ctx, resourceMaps, client)
return CreatePreparedStatements(ctx, currentResourceMaps, client)

}
4 changes: 3 additions & 1 deletion workspace/workspace_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ func (w *Workspace) handleFileWatcherEvent(client db_common.Client, events []fsn
resourceMaps := w.GetResourceMaps()
// if resources have changed, update metadata tables and prepared statements
if !prevResourceMaps.Equals(resourceMaps) {
// first update prepared statements
db_common.UpdatePreparedStatements(context.Background(), prevResourceMaps, resourceMaps, client)
// then update the introspection tables
db_common.UpdateMetadataTables(resourceMaps, client)
db_common.UpdatePreparedStatements(context.Background(), resourceMaps, client)
}
w.raiseReportChangedEvents(w.getPanelMap(), prevPanels, w.getReportMap(), prevReports)
}
Expand Down

0 comments on commit 5994113

Please sign in to comment.