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

メンターはデフォルトでQ&AをWatch中にする #3120

Merged

Conversation

yamadaab
Copy link
Contributor

@yamadaab yamadaab commented Aug 11, 2021

#2874

機能
どのユーザーが質問を保存しても、メンターさんのみ自動的に「Watch中」になります。

修正点

  • questions_controllerを修正しました。
  • createメソッド内に「watch中」にする「change_to_watching_for_mentor_only」メソッドを追加しました。
  • 質問が保存された後に、メンターさんをUserテーブルから検索します。
  • 検索したメンターさんと質問を紐付けます。

@yamadaab yamadaab changed the title メンターのみQ&AをWatch中にする機能 メンターはデフォルトでQ&AをWatch中にする Aug 12, 2021
@yamadaab yamadaab requested a review from udaikue August 12, 2021 02:15
@yamadaab yamadaab marked this pull request as ready for review August 12, 2021 02:15
@yamadaab
Copy link
Contributor Author

@udaikue
お手隙の時にレビューをお願い致します。🙇‍♂️
オブジェクト指向など、懸念点はあるのですが駒形さんの意見に合わせて修正しようと思っています。
そのため、機能についてレビューして頂けると助かります🙇‍♂️

Copy link
Contributor

@udaikue udaikue left a comment

Choose a reason for hiding this comment

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

確認しました!いいと思います〜🙂

@yamadaab
Copy link
Contributor Author

@udaikue
ありがとうございます!

@komagata
レビューお願い致します。🙇‍♂️

@@ -95,4 +96,14 @@ def questions_property
QuestionsProperty.new('未解決の質問一覧', '未解決の質問はまだありません。')
end
end

def change_to_watching_for_mentor_only
mentors = User.where(mentor: true)
Copy link
Member

Choose a reason for hiding this comment

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

mentorsってsocpeがあるかも?(なかったら作っちゃって大丈夫です)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Userクラスに「mentor」というscopeがありました。User.mentorで同じことができました!
ありがとうございます。

@@ -95,4 +96,14 @@ def questions_property
QuestionsProperty.new('未解決の質問一覧', '未解決の質問はまだありません。')
end
end

def change_to_watching_for_mentor_only
Copy link
Member

Choose a reason for hiding this comment

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

英語として不自然かも?watchを動詞として使っちゃっていいと思います~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

「メンターのみ視聴中に変更する」でdeeplで翻訳するとこの訳になりました(^^;
Watchingから始めた場合でも考えたのですが、うまいメソッド名が思いつきませんでした。すみません🙇‍♂️
スクリーンショット 2021-08-20 15 32 03

Copy link
Member

Choose a reason for hiding this comment

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

直訳は要注意です。
しっかり意味を理解した上で、なるべく端的に表現する言葉を最後まで考えてみてください。
Rubyでは「名前重要」が作者の座右の銘になるほど重要視されているので、Ruby業界の人はみんな結構このあたりにうるさい感じです🤭

@yamadaab yamadaab force-pushed the feature/Mentors_will_be_on_Watch_for_QandA_by_default branch from a9b94da to f8647af Compare August 20, 2021 06:20
@@ -95,4 +96,13 @@ def questions_property
QuestionsProperty.new('未解決の質問一覧', '未解決の質問はまだありません。')
end
end

def watching_mentors_only
Copy link
Member

Choose a reason for hiding this comment

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

メソッド名は動詞が原則なので英語の文法的にちょっとおかしいかもです。

watchable: @question
)
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

1. メンターの数だけSQLが発行される(N+1)

メンターが10人いると10回INSERT文が発行されて遅くなってしまいます。

insert_all! を使って一回のSQLでレコードを追加するように直す方が良さそうです。

2. Watchの登録が途中で終わる可能性がある

メンターが10人いて、5人目のWatch登録でエラーになると残りはWatchにならずにエラー画面が表示されてしまいそうです。
対応方針は @komagata さんに伺った方が良いかも。

  1. 現状のまま途中でエラーが出たら、そのままエラーにする
    • Watchの登録に失敗することは稀だと思うので、エラー出てから考えるでも良い気はします
  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.

@sinsoku
アドバイスありがとうございます!
insert_allを使用する形に修正してみました(^^
但し、rubocopにisert_allは使わないようにメッセージが出てしまいましたので、駒形さんに相談して更に対応したい思います。🙇‍♂️
rubocopのメッセージ:Rails/SkipsModelValidations: Avoid using insert_all because it skips validations.

@komagata
遅くなりすみません。「質問を投稿するとメンターのみ"Watch中"にする」機能を修正しました。
メソッド名の変更しました。すみませんが、以下の確認をお願い致します。

  • メソッド名:create_mentors_watchは妥当でしょうか。
  • insert_allは使用しない方がよろしいでしょうか。
  • sinsokuさんのご指摘のように「メンターが10人いて、5人目のWatch登録でエラーになると残りはWatchにならずにエラー画面が表示されてしまいそう」のような想定をした方がよろしいでしょうか。それとも、別の想定がよろしいでしょうか。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sinsoku
ご連絡遅くなってすみません。
駒形さんにも伺って、今回はrubocopの指摘を優先することとなりました。
とは言え、アドバイスとても勉強になりました。ありがとうございました。🙇‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

@yamadaab 大変申し訳ありません、改めて考えてみたところメンター12人ぐらいいるので速度的にinsert_allを使った方がいいように思いました。

お手数ですがinsert_allにしてrubocopの指摘はコメントを使って無効化していただければありがたいです。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@komagata
時間がかかりすみません。rubocopに手間取りましたが、無事に修正できたと思います。
ご確認よろしくお願い致します。

@yamadaab yamadaab force-pushed the feature/Mentors_will_be_on_Watch_for_QandA_by_default branch from 3cf4814 to 2b69468 Compare September 3, 2021 07:24
@yamadaab yamadaab force-pushed the feature/Mentors_will_be_on_Watch_for_QandA_by_default branch 3 times, most recently from eb3ed64 to 6c7e7c6 Compare September 16, 2021 07:36
@yamadaab
Copy link
Contributor Author

@komagata
insert_allの修正と、「mentorをWatch中にする」メソッド名を「create_mentor_watch」としてみました。
event_callbacks.rbの「create_author_watch」というメソッドと揃えてみました。
ご確認よろしくお願い致します🙇‍♂️

Comment on lines 101 to 106
User.mentor.each do |mentor|
watch = Watch.new(
user: mentor,
watchable: @question
)
watch.save!
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
User.mentor.each do |mentor|
watch = Watch.new(
user: mentor,
watchable: @question
)
watch.save!
User.mentor.each do |mentor|
Watch.create!(
user: mentor,
watchable: @question
)

こういう感じでいいかもです〜

@yamadaab
Copy link
Contributor Author

@komagata
修正が完了しました。
ただし、「提出物にブックマーク機能がほしい。提出物個別ページにブックマークボタンを設置。 #3232」のプルリクで追加されたテストのみ通らない状態のようです。(^^;

このような場合はどのようにすると良いでしょうか。
レビューを継続して頂いてもよろしいのでしょうか(^^;
すみませんが、ご確認よろしくお願い致しますm(__)m

@komagata
Copy link
Member

@yamadaab Merge Commitができちゃってるかも?

スクリーンショット 2021-09-23 13 56 36

@yamadaab yamadaab force-pushed the feature/Mentors_will_be_on_Watch_for_QandA_by_default branch from 44af325 to 14ebae6 Compare September 27, 2021 09:11
@yamadaab
Copy link
Contributor Author

yamadaab commented Sep 27, 2021

@komagata
指摘頂いた箇所の修正が終わり、マージコミットも修正が終わりました。
先ほどはお騒がせしました。
確認のほどよろしくお願い致します。🙇‍♂️

@yamadaab yamadaab force-pushed the feature/Mentors_will_be_on_Watch_for_QandA_by_default branch from 14ebae6 to fd214e8 Compare October 2, 2021 12:11
@yamadaab yamadaab force-pushed the feature/Mentors_will_be_on_Watch_for_QandA_by_default branch from ee5898e to 33183b2 Compare October 4, 2021 00:39
Copy link
Member

@komagata komagata left a comment

Choose a reason for hiding this comment

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

確認しました、OKですー🙆‍♂️

@komagata komagata merged commit bb90f2d into main Oct 4, 2021
@komagata komagata deleted the feature/Mentors_will_be_on_Watch_for_QandA_by_default branch October 4, 2021 06:58
@github-actions github-actions bot mentioned this pull request Oct 4, 2021
14 tasks
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.

4 participants