-
Notifications
You must be signed in to change notification settings - Fork 12
Optimize queries #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Optimize queries #121
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6f9d0a5
init
dbaseqp f0bd457
only compute after round
dbaseqp 12f5cad
refactor
dbaseqp 361851c
remove md
dbaseqp a7398d5
more optimized
dbaseqp 6a6fe35
avoid possibly spawning multiple refreshes
dbaseqp 93f964c
Merge branch 'main' of https://github.com/dbaseqp/quotient into optim…
dbaseqp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package integration | ||
|
|
||
| import ( | ||
| "quotient/engine/db" | ||
| "quotient/tests/testutil" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestMaterializedViewLifecycle(t *testing.T) { | ||
| if testing.Short() { | ||
| t.Skip("skipping integration test in short mode") | ||
| } | ||
|
|
||
| // Start PostgreSQL connection | ||
| pgContainer := testutil.StartPostgres(t) | ||
|
|
||
| // Initialize database connection | ||
| // This calls createCumulativeScoresView() internally, which now includes the initial REFRESH | ||
| db.Connect(pgContainer.ConnectionString()) | ||
|
|
||
| // Data cleanup | ||
| err := db.ResetScores() | ||
| require.NoError(t, err, "ResetScores should succeed") | ||
|
|
||
| t.Run("refresh with zero rows", func(t *testing.T) { | ||
| // The view should operate correctly even with no data | ||
| err := db.RefreshScoresMaterializedView() | ||
| require.NoError(t, err, "RefreshScoresMaterializedView should succeed with 0 rows") | ||
| }) | ||
|
|
||
| t.Run("refresh with data", func(t *testing.T) { | ||
| // Add a team | ||
| team := db.TeamSchema{ | ||
| Name: "ViewTestTeam", | ||
| Active: true, | ||
| Identifier: "vt1", | ||
| } | ||
| teamCreated, err := db.CreateTeam(team) | ||
| require.NoError(t, err) | ||
|
|
||
| // Create a round with a result | ||
| check := db.ServiceCheckSchema{ | ||
| TeamID: teamCreated.ID, | ||
| RoundID: 1, | ||
| ServiceName: "test-service", | ||
| Points: 10, | ||
| Result: true, | ||
| } | ||
|
|
||
| round := db.RoundSchema{ | ||
| ID: 1, | ||
| StartTime: time.Now(), | ||
| Checks: []db.ServiceCheckSchema{check}, | ||
| } | ||
|
|
||
| _, err = db.CreateRound(round) | ||
| require.NoError(t, err, "should save round to database") | ||
|
|
||
| // Refresh should succeed with data | ||
| err = db.RefreshScoresMaterializedView() | ||
| require.NoError(t, err, "RefreshScoresMaterializedView should succeed with data") | ||
|
|
||
| // Optional: We could verify data via db.GetServiceCheckSumByRound() if we wanted to be thorough | ||
| // but the main point here is that the REFRESH command doesn't throw an error. | ||
| }) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.