Skip to content

Commit

Permalink
fix: add missing indexes (#2973)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik committed Dec 20, 2022
1 parent 83131fc commit bbb3995
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE INDEX selfservice_errors_nid_idx ON selfservice_errors (id, nid);

DROP INDEX selfservice_errors_errors_nid_id_idx;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE INDEX selfservice_errors_nid_idx ON selfservice_errors (id, nid);

-- needed for foreign key constraint, was there before implicitly
CREATE INDEX selfservice_errors_nid_only_idx ON selfservice_errors (nid);

DROP INDEX selfservice_errors_errors_nid_id_idx ON selfservice_errors;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE INDEX selfservice_errors_errors_nid_id_idx ON selfservice_errors (nid, id);

-- This index is not needed anymore, because the primary ID index together with the new index cover all queries.
DROP INDEX selfservice_errors_nid_idx ON selfservice_errors;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE INDEX selfservice_errors_errors_nid_id_idx ON selfservice_errors (nid, id);

-- This index is not needed anymore, because the primary ID index together with the new index cover all queries.
DROP INDEX selfservice_errors_nid_idx;
13 changes: 2 additions & 11 deletions persistence/sql/persister_courier.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"database/sql"
"encoding/json"
"fmt"

"github.com/gobuffalo/pop/v6"
"github.com/gofrs/uuid"
Expand Down Expand Up @@ -137,11 +136,7 @@ func (p *Persister) SetMessageStatus(ctx context.Context, id uuid.UUID, ms couri
defer span.End()

count, err := p.GetConnection(ctx).RawQuery(
// #nosec G201
fmt.Sprintf(
"UPDATE %s SET status = ? WHERE id = ? AND nid = ?",
"courier_messages",
),
"UPDATE courier_messages SET status = ? WHERE id = ? AND nid = ?",
ms,
id,
p.NetworkID(ctx),
Expand All @@ -162,11 +157,7 @@ func (p *Persister) IncrementMessageSendCount(ctx context.Context, id uuid.UUID)
defer span.End()

count, err := p.GetConnection(ctx).RawQuery(
// #nosec G201
fmt.Sprintf(
"UPDATE %s SET send_count = send_count + 1 WHERE id = ? AND nid = ?",
"courier_messages",
),
"UPDATE courier_messages SET send_count = send_count + 1 WHERE id = ? AND nid = ?",
id,
p.NetworkID(ctx),
).ExecWithCount()
Expand Down

0 comments on commit bbb3995

Please sign in to comment.