Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def destroy
# 制限をかけておく
redirect_to admin_users_url, alert: '自分自身を削除する場合、退会から処理を行ってください。' if current_user.id == params[:id]
user = User.find(params[:id])
Newspaper.publish(:learning_destroy, { user: })
ActiveSupport::Notifications.instrument('learning.destroy', user:)
user.destroy
redirect_to admin_users_url, notice: "#{user.name} さんを削除しました。"
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/practices/learning_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def update
status = learning.new_record? ? :created : :ok

if learning.save
Newspaper.publish(:learning_create, { user: learning.user })
ActiveSupport::Notifications.instrument('learning.create', user: learning.user)
notify_to_chat_for_employment_counseling(learning) if status == :created && learning.practice.title == '就職相談部屋を作る'
head status
else
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def create

if @report.save_uniquely
ActiveSupport::Notifications.instrument('report.create', report: @report)
Newspaper.publish(:report_save, { report: @report })
redirect_to redirect_url(@report), notice: notice_message(@report), flash: flash_contents(@report)
else
render :new
Expand All @@ -77,7 +76,6 @@ def update

if @report.save_uniquely
ActiveSupport::Notifications.instrument('report.update', report: @report)
Newspaper.publish(:report_save, { report: @report })
redirect_to redirect_url(@report), notice: notice_message(@report), flash: flash_contents(@report)
else
@report.wip = before_wip_status
Expand All @@ -87,7 +85,7 @@ def update

def destroy
@report.destroy
Newspaper.publish(:report_destroy, { report: @report })
ActiveSupport::Notifications.instrument('report.destroy', report: @report)
redirect_to reports_url, notice: '日報を削除しました。'
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/learning_cache_destroyer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class LearningCacheDestroyer
def call(payload)
def call(_name, _started, _finished, _unique_id, payload)
user = payload[:user]
Rails.cache.delete "/model/user/#{user.id}/completed_percentage"
Rails.logger.info "[LearningCacheDestroyer] Cache destroyed for user #{user.id}"
Expand Down
2 changes: 1 addition & 1 deletion app/models/sad_streak_updater.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class SadStreakUpdater
def call(payload)
def call(_name, _started, _finished, _unique_id, payload)
report = payload[:report]
report.user.update_sad_streak
end
Expand Down
8 changes: 8 additions & 0 deletions config/initializers/active_support_notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
ActiveSupport::Notifications.subscribe('answer.create', NotifierToWatchingUser.new)
ActiveSupport::Notifications.subscribe('event.create', EventOrganizerWatcher.new)
ActiveSupport::Notifications.subscribe('regular_event.create', RegularEventOrganizerWatcher.new)
sad_streak_updater = SadStreakUpdater.new
ActiveSupport::Notifications.subscribe('report.create', sad_streak_updater)
ActiveSupport::Notifications.subscribe('report.update', sad_streak_updater)
Comment on lines +10 to +11
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

背景を確認させてください!
今回、元々の :report_save イベントを report.createreport.update に分けて処理されている意図を教えていただけますか?
私としては、一つのイベントとして report.save として書き換えるでも良いかなと思ったのですが、今回分けることにした理由があれば教えていただけると嬉しいです🙏

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@smallmonkeykey

背景としては、当初はreport.saveで書いていたのですが、メインの変更を取り込んだときにコンフリクトが起きて、コントローラにあるイベントの発行側のコード(ActiveSupport::Notifications.instrument)がreport.createreport.updateでマージされていることに気がついた、というものです。担当箇所が一部他のissueと被っていた感じです。

調べたところ、こちらのプルリクエストでのやり取りを見つけました👀Pull Request #8869
こちらコメントのリンクです👀

迷ったのですが、この書き方で既に合意が取れているのが上記のコメントのやり取りでわかったのでそれに合わせました。

事前に説明しておくべきでした。申し訳ありません🙏

ActiveSupport::Notifications.subscribe('report.destroy', sad_streak_updater)
ActiveSupport::Notifications.subscribe('report.create', FirstReportNotifier.new)
ActiveSupport::Notifications.subscribe('report.update', FirstReportNotifier.new)
ActiveSupport::Notifications.subscribe('report.create', ReportNotifier.new)
Expand All @@ -30,4 +34,8 @@
page_notifier = PageNotifier.new
ActiveSupport::Notifications.subscribe('page.create', page_notifier)
ActiveSupport::Notifications.subscribe('page.update', page_notifier)

learning_cache_destroyer = LearningCacheDestroyer.new
ActiveSupport::Notifications.subscribe('learning.create', learning_cache_destroyer)
ActiveSupport::Notifications.subscribe('learning.destroy', learning_cache_destroyer)
end
8 changes: 0 additions & 8 deletions config/initializers/newspaper.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
# frozen_string_literal: true

Rails.configuration.after_initialize do
sad_streak_updater = SadStreakUpdater.new
Newspaper.subscribe(:report_save, sad_streak_updater)
Newspaper.subscribe(:report_destroy, sad_streak_updater)

learning_cache_destroyer = LearningCacheDestroyer.new
Newspaper.subscribe(:learning_create, learning_cache_destroyer)
Newspaper.subscribe(:learning_destroy, learning_cache_destroyer)

answer_cache_destroyer = AnswerCacheDestroyer.new
Newspaper.subscribe(:answer_save, answer_cache_destroyer)
Newspaper.subscribe(:answer_destroy, answer_cache_destroyer)
Expand Down