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

FIX: Update Discobot's UserProfile#bio_raw when default locale changes #26045

Merged
merged 1 commit into from Mar 6, 2024

Conversation

tgxworld
Copy link
Contributor

@tgxworld tgxworld commented Mar 6, 2024

Why this change?

When a site's default locale is changed, Discobot's UserProfile#bio_raw is not
changed and we have gotten reports about this.

What does this change do?

This change adds a DiscourseEvent.on(:site_setting_changed) callback
which watches for changes to the default_locale site setting and
updates Discobot's UserProfile#bio_raw when it changes.

next if profile.blank?

new_bio = I18n.with_locale(new_value) { I18n.t("discourse_narrative_bot.bio") }
profile.update!(bio_raw: new_bio) if profile.bio_raw != new_bio
Copy link
Contributor

Choose a reason for hiding this comment

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

Extremely minor, but I wonder if AR will prevent this kind of noop before reaching out to the DB?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

O good catch! AR actually does a noop.

[5] pry(main)> profile.update!(bio_raw: profile.bio_raw)
  TRANSACTION (0.2ms)  BEGIN
  User Load (4.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = -2 LIMIT 1
  TRANSACTION (0.2ms)  COMMIT
=> true

Copy link
Contributor

@martin-brennan martin-brennan left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@tgxworld tgxworld force-pushed the update_discobot_bio_raw_when_default_locale_changes branch from f5fd054 to 2f1ecd2 Compare March 6, 2024 03:23
Why this change?

When a site's default locale is changed, Discobot's `UserProfile#bio_raw` is not
changed and we have gotten reports about this.

What does this change do?

This change adds a `DiscourseEvent.on(:site_setting_changed)` callback
which watches for changes to the `default_locale` site setting and
updates Discobot's `UserProfile#bio_raw` when it changes.
@tgxworld tgxworld force-pushed the update_discobot_bio_raw_when_default_locale_changes branch from 2f1ecd2 to ef831ea Compare March 6, 2024 03:31
@tgxworld tgxworld merged commit 7f7ef60 into main Mar 6, 2024
16 checks passed
@tgxworld tgxworld deleted the update_discobot_bio_raw_when_default_locale_changes branch March 6, 2024 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants