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

Don't filter labels by label_type which is being removed #689

Merged
merged 1 commit into from
Nov 16, 2022
Merged
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
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