Skip to content

Commit

Permalink
Don't filter labels by label_type which is being removed
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Nov 16, 2022
1 parent 557e89d commit 26d739e
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions core/models/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (l *Label) Name() string { return l.l.Name }
func loadLabels(ctx context.Context, db sqlx.Queryer, orgID OrgID) ([]assets.Label, error) {
start := time.Now()

rows, err := db.Queryx(selectLabelsSQL, orgID)
rows, err := db.Queryx(sqlSelectLabels, orgID)
if err != nil {
return nil, errors.Wrapf(err, "error querying labels for org: %d", orgID)
}
Expand All @@ -57,35 +57,24 @@ func loadLabels(ctx context.Context, db sqlx.Queryer, orgID OrgID) ([]assets.Lab
return labels, nil
}

const selectLabelsSQL = `
SELECT ROW_TO_JSON(r) FROM (SELECT
id,
uuid,
name
FROM
msgs_label
WHERE
org_id = $1 AND
is_active = TRUE AND
label_type = 'L'
ORDER BY
name ASC
const sqlSelectLabels = `
SELECT ROW_TO_JSON(r) FROM (
SELECT id, uuid, name
FROM msgs_label
WHERE org_id = $1 AND is_active = TRUE
ORDER BY name ASC
) r;
`

// AddMsgLabels inserts the passed in msg labels to our db
func AddMsgLabels(ctx context.Context, tx *sqlx.Tx, adds []*MsgLabelAdd) error {
err := BulkQuery(ctx, "inserting msg labels", tx, insertMsgLabelsSQL, adds)
err := BulkQuery(ctx, "inserting msg labels", tx, sqlInsertMsgLabels, adds)
return errors.Wrapf(err, "error inserting new msg labels")
}

const insertMsgLabelsSQL = `
INSERT INTO
msgs_msg_labels(msg_id, label_id)
VALUES(:msg_id, :label_id)
ON CONFLICT
DO NOTHING
`
const sqlInsertMsgLabels = `
INSERT INTO msgs_msg_labels(msg_id, label_id) VALUES(:msg_id, :label_id)
ON CONFLICT DO NOTHING`

// MsgLabelAdd represents a single label that should be added to a message
type MsgLabelAdd struct {
Expand Down

0 comments on commit 26d739e

Please sign in to comment.