Skip to content
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

update data prune query to use 'where not exists' instead of 'not in' #541

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tgapi/pkg/handlers/node_upgrade.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package handlers

import (
"database/sql"
"encoding/json"
"errors"
"net/http"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -43,6 +45,10 @@ func GetNodeUpgradeCommand(w http.ResponseWriter, r *http.Request) {

command, err := testinstance.GetNodeUpgradeCommand(instanceID, nodeName)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
JSON(w, 404, nil)
return
}
logger.Error(err)
JSON(w, 500, err)
return
Expand Down
8 changes: 4 additions & 4 deletions tgapi/pkg/persistence/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ WHERE ref = any (array(SELECT ref FROM testrun WHERE created_at < $1 ORDER BY cr
deletedRows += int(deleted)
log.Printf("Deleted %d testrun entries", deleted)

// delete test runs that do not have a matching testrun
result, err = pg.Exec("DELETE FROM testinstance WHERE testrun_ref NOT IN (SELECT ref FROM testrun)")
// delete test instances that do not have a matching testrun
result, err = pg.Exec("DELETE FROM testinstance WHERE NOT EXISTS (SELECT FROM testrun WHERE testinstance.testrun_ref = testrun.ref)")
if err != nil {
return -1, -1, fmt.Errorf("error deleting testinstance entries: %v", err)
}
Expand All @@ -53,7 +53,7 @@ WHERE ref = any (array(SELECT ref FROM testrun WHERE created_at < $1 ORDER BY cr
log.Printf("Deleted %d testinstance entries", deleted)

// delete test upgrades/nodes that do not have a matching testinstance
result, err = pg.Exec("DELETE FROM clusternode WHERE testinstance_id NOT IN (SELECT id FROM testinstance)")
result, err = pg.Exec("DELETE FROM clusternode WHERE NOT EXISTS (SELECT FROM testinstance WHERE clusternode.testinstance_id = testinstance.id)")
if err != nil {
return -1, -1, fmt.Errorf("error deleting clusternode entries: %v", err)
}
Expand All @@ -64,7 +64,7 @@ WHERE ref = any (array(SELECT ref FROM testrun WHERE created_at < $1 ORDER BY cr
deletedRows += int(deleted)
log.Printf("Deleted %d clusternode entries", deleted)

result, err = pg.Exec("DELETE FROM testupgrade WHERE id NOT IN (SELECT id FROM testinstance)")
result, err = pg.Exec("DELETE FROM testupgrade WHERE NOT EXISTS (SELECT FROM testinstance WHERE testupgrade.id = testinstance.id)")
if err != nil {
return -1, -1, fmt.Errorf("error deleting testupgrade entries: %v", err)
}
Expand Down
Loading