Skip to content

tags: migration to fix tags case differences

Rodrigo Souto requested to merge diguliu/noosfero:tags-case into next

Whenever you have 2 or more tags with the same name but different cases, ActsAsTaggableOn returns an empty list of objects tagged with either of the tags. To solve this problem, we must not have tags with different cases stored.

Performance was my primal concern on this migration since we have instances that have over 130k tags registered. So I decided to convert every tag to lower case. This is the fastest way I could conceive this migration and still it might take a lot of time. Here is basic resume of what it does:

  1. Find all tags that do not have a downcased form already created - [1 fast select query].
  2. Create a downcased version of the above queries - [x slow update queries but x is usually low because a minority of tags have odd case and all different cases of a single word generate only 1 query].
  3. Update taggings relations based on new ids - [1 slow update and 2 slow join queries].
  4. Updates the taggings_count of every tag - [1 slow update with z fast selects]
  5. Delete all unused tags tags - [1 slow delete query].

x: number of new downcased tags created.
y: number of oddcased tags.
z: number of tags.

Merge request reports