From 9583f038e3d9f0fda95e73108ca0661773832ab1 Mon Sep 17 00:00:00 2001 From: Raiden Shogun Date: Fri, 1 Dec 2023 15:14:42 +0100 Subject: [PATCH] fix: refreshing materialized view --- .gitignore | 2 +- pkg/db/postgres.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1e7c54b..407e20d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ testdata/docker-test/testout.json testdata/docker-test/testout.html ./gopogh cmd/gopogh-server/gopogh-server -.vscode \ No newline at end of file +.vscode/ \ No newline at end of file diff --git a/pkg/db/postgres.go b/pkg/db/postgres.go index f9af77e..301d564 100644 --- a/pkg/db/postgres.go +++ b/pkg/db/postgres.go @@ -150,8 +150,15 @@ func (m *Postgres) createMaterializedView(env string, viewName string) error { WHERE Result != 'skip' AND EnvName = '%s' AND TestTime >= NOW() - INTERVAL '90 days' `, viewName, env) - _, err := m.db.Exec(createView) - return err + if _, err := m.db.Exec(createView); err != nil { + return err + } + // refresh the materialzed view + refreshView := fmt.Sprintf("REFRESH MATERIALIZED VIEW %s ;", viewName) + if _, err := m.db.Exec(refreshView); err != nil { + return err + } + return nil } // GetTestCharts writes the individual test chart data to a map with the keys flakeByDay and flakeByWeek