Skip to content

Commit

Permalink
Avoided doing cleanup in a transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-asplin-met-no committed Sep 26, 2024
1 parent 0ed7437 commit 62b40b9
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions datastore/datastore/storagebackend/postgresql/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,7 @@ func cleanup(db *sql.DB) error {
log.Println("db cleanup started")
start := time.Now()

// start transaction
tx, err := db.Begin()
if err != nil {
return fmt.Errorf("db.Begin() failed: %v", err)
}
defer tx.Rollback()
var err error

// --- BEGIN define removal functions ----------------------------------

Expand All @@ -362,7 +357,7 @@ func cleanup(db *sql.DB) error {
WHERE (obstime_instant < to_timestamp(%d)) OR (obstime_instant > to_timestamp(%d))
`, loTime.Unix(), hiTime.Unix())

_, err = tx.Exec(cmd)
_, err = db.Exec(cmd)
if err != nil {
return fmt.Errorf(
"tx.Exec() failed when removing observations outside valid range: %v", err)
Expand All @@ -382,7 +377,7 @@ func cleanup(db *sql.DB) error {
)
`, tableName, tableName, fkName)

_, err = tx.Exec(cmd)
_, err = db.Exec(cmd)
if err != nil {
return fmt.Errorf(
"tx.Exec() failed when removing unreferenced rows from %s: %v", tableName, err)
Expand Down Expand Up @@ -415,11 +410,6 @@ func cleanup(db *sql.DB) error {

// --- END apply removal functions ------------------------------------------

// commit transaction
if err = tx.Commit(); err != nil {
return fmt.Errorf("tx.Commit() failed: %v", err)
}

log.Printf("db cleanup complete after %v", time.Since(start))

return nil
Expand Down

1 comment on commit 62b40b9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API Unit Test Coverage Report
FileStmtsMissCoverMissing
\_\_init\_\_.py00100% 
datastore_pb2.py614821%34–81
datastore_pb2_grpc.py542750%15–16, 19, 57–72, 105–107, 112–114, 119–121, 126–128, 132–157, 195, 222, 249, 276
export_metrics.py100100% 
grpc_getter.py201145%15–19, 23–26, 30–32, 36–38
locustfile.py15150%1–31
main.py43784%45, 50, 60, 70–71, 81–82
metadata_endpoints.py632954%45–54, 58, 85, 100–216, 220
response_classes.py50100% 
utilities.py1815669%20, 38, 45, 67–70, 78–89, 94–101, 121, 125, 127, 154, 157, 166, 184–185, 189, 205–210, 215, 219–220, 224–226, 232–240, 250–253, 259–260, 272–276, 299, 304, 317
custom_geo_json
   edr_feature_collection.py60100% 
formatters
   \_\_init\_\_.py110100% 
   covjson.py57198%88
   geojson.py17288%21, 46
openapi
   custom_dimension_examples.py40100% 
   edr_query_parameter_descriptions.py110100% 
   openapi_examples.py130100% 
routers
   \_\_init\_\_.py00100% 
   edr.py102496%350–351, 441–442
   feature.py471960%99–132, 148–153, 159–181
TOTAL72021970% 

API Unit Test Coverage Summary

Tests Skipped Failures Errors Time
30 0 💤 0 ❌ 0 🔥 1.914s ⏱️

Please sign in to comment.