Deprioritize label when archived

What does this MR do and why?

We need to unprioritize labels when they are archived. See !196443 (comment 2612172874) for more information:

Remove priority when label is archived

It doesn't make sense IMO for an archived label to be a prioritized label, archiving a label should simultaneously remove any prioritization applied as it's essentially out of use. I can see the use case here where you have existing items, but using it for priority seems antithetical to the label being out of use.

This MR makes sure that:

  • the priorities are deleted when a label is set to archived.
  • it's no longer possible to prioritize archived labels.

It does NOT:

  • Change the structure (All / Archived / Subscribed) of the labels index. I'll do this in a separate MR to keep things small. Afterwards, the view will look a bit more clean again. Right now it can look messy when archived and unarchived labels are mixed in All, since some can be prioritized and some cannot.

🛠️ with ❤️ at Siemens

References

Screenshots or screen recordings

prevent-prioritizing

How to set up and validate locally

  1. Enable feature flag via rails c:
Feature.enable(:labels_archive)
  1. Archive a label: Go to Any project > Manage > Labels and edit a prioritized label in the three dot dropdown. Check the Archived checkbox and save the label.
  2. It should no longer be prioritized.
  3. You should also see that in the All tab archived labels no longer have the star to prioritize them.

Database Query Plan

I had to manually construct this, as .explain does not directly work on delete_all. Also, this is from my local instance.

Explain
EXPLAIN DELETE FROM "label_priorities" WHERE "label_priorities"."label_id" = 2 

Delete on label_priorities  (cost=0.15..6.26 rows=0 width=0)
  ->  Index Scan using index_label_priorities_on_label_id on label_priorities  (cost=0.15..6.26 rows=6 width=6)
        Index Cond: (label_id = 2)"}

MR acceptance checklist

MR Checklist ( @nwittstruck)

Related to #4233

Edited by Nicholas Wittstruck

Merge request reports

Loading