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

Make custom emoji domains case insensitive #9351 #9474

Merged
merged 4 commits into from
Dec 11, 2018

Conversation

Esteth
Copy link
Contributor

@Esteth Esteth commented Dec 8, 2018

Make custom emoji domains case insensitive to fix #9531

Postgres supports CITEXT, but migrating the database from TEXT to CITEXT could require a whole table lock or an interim migration with dual writes.

Instead, it should be fine to migrate existing rows to lowercase one-by-one, input only lowercase input in future, and do comparisons against lowercase input.

This is my first pull request for mastodon and I haven't worked in Ruby in a long time - please let me know if I'm missing something!

@@ -0,0 +1,5 @@
class DowncaseCustomEmojiDomains < ActiveRecord::Migration[5.2]
def change
CustomEmoji.update_all('domain = lower(domain)')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use in_batches.update_all to prevent table lock ups

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, I didn't know this existed!

@@ -0,0 +1,5 @@
class DowncaseCustomEmojiDomains < ActiveRecord::Migration[5.2]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add disable_ddl_transaction! to use no locking around the updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'm learning a lot about ActiveRecord migrations :)

db/schema.rb Outdated
@@ -336,9 +336,9 @@
create_table "mutes", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "hide_notifications", default: true, null: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this is about, the version string update is OK but this seems unnecessary, you can manually switch it around.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this is the result of a bad merge. My bad for not seeing it!

Reverted

Also revert spurious schema change.
Copy link
Contributor Author

@Esteth Esteth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Gargron - I've forgotten so much about rails!

@@ -0,0 +1,5 @@
class DowncaseCustomEmojiDomains < ActiveRecord::Migration[5.2]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'm learning a lot about ActiveRecord migrations :)

@@ -0,0 +1,5 @@
class DowncaseCustomEmojiDomains < ActiveRecord::Migration[5.2]
def change
CustomEmoji.update_all('domain = lower(domain)')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, I didn't know this existed!

db/schema.rb Outdated
@@ -336,9 +336,9 @@
create_table "mutes", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "hide_notifications", default: true, null: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this is the result of a bad merge. My bad for not seeing it!

Reverted

@Gargron Gargron merged commit 7d00e4e into mastodon:master Dec 11, 2018
hiyuki2578 pushed a commit to ProjectMyosotis/mastodon that referenced this pull request Oct 2, 2019
* Make custom emoji domains case sensitive mastodon#9351

* Fixup style in downcase_domain to comply with codeclimate.

* switch if! to unless

* Don't use transactions, operate in batches.

Also revert spurious schema change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants