Skip to content

Commit

Permalink
fix inefficient query
Browse files Browse the repository at this point in the history
postgres was doing a scan of 1M rows fml
  • Loading branch information
alexzorin committed Mar 15, 2022
1 parent 3cfc2a4 commit d8e836a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion web/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (s *server) listenForTests(dsn string) error {

func (s *server) vacuumTests() {
for {
if _, err := s.db.Exec(`UPDATE tests set status = 'Cancelled' WHERE status NOT IN ('Cancelled','Complete') AND created_at < now() - interval '30 minutes';`); err != nil {
if _, err := s.db.Exec(`UPDATE tests set status = 'Cancelled' WHERE status IN ('Queued','Processing') AND created_at < now() - interval '30 minutes';`); err != nil {
log.Printf("Failed to vacuum: %v", err)
}
time.Sleep(10 * time.Second)
Expand Down
1 change: 1 addition & 0 deletions web/db_migrations/20180428_InitialSchema.up.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- Warning: update server.vacuumTests() if changing this enum.
CREATE TYPE test_status AS ENUM ('Queued', 'Processing', 'Complete', 'Cancelled');

CREATE TABLE tests (
Expand Down

0 comments on commit d8e836a

Please sign in to comment.