Skip to content

Commit

Permalink
Merge pull request #689 from nyaruka/flatten_labels
Browse files Browse the repository at this point in the history
Don't filter labels by `label_type` which is being removed
  • Loading branch information
rowanseymour authored Nov 16, 2022
2 parents 557e89d + 26d739e commit b679d22
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 b679d22

Please sign in to comment.