-
Notifications
You must be signed in to change notification settings - Fork 72
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
メンターはデフォルトでQ&AをWatch中にする #3120
Conversation
@udaikue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確認しました!いいと思います〜🙂
@@ -95,4 +96,14 @@ def questions_property | |||
QuestionsProperty.new('未解決の質問一覧', '未解決の質問はまだありません。') | |||
end | |||
end | |||
|
|||
def change_to_watching_for_mentor_only | |||
mentors = User.where(mentor: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mentorsってsocpeがあるかも?(なかったら作っちゃって大丈夫です)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
英語として不自然かも?watchを動詞として使っちゃっていいと思います~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直訳は要注意です。
しっかり意味を理解した上で、なるべく端的に表現する言葉を最後まで考えてみてください。
Rubyでは「名前重要」が作者の座右の銘になるほど重要視されているので、Ruby業界の人はみんな結構このあたりにうるさい感じです🤭
a9b94da
to
f8647af
Compare
@@ -95,4 +96,13 @@ def questions_property | |||
QuestionsProperty.new('未解決の質問一覧', '未解決の質問はまだありません。') | |||
end | |||
end | |||
|
|||
def watching_mentors_only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
メソッド名は動詞が原則なので英語の文法的にちょっとおかしいかもです。
watchable: @question | ||
) | ||
end | ||
end |
There was a problem hiding this comment.
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 さんに伺った方が良いかも。
- 現状のまま途中でエラーが出たら、そのままエラーにする
- Watchの登録に失敗することは稀だと思うので、エラー出てから考えるでも良い気はします
- エラーを記録しつつ、残りの登録を継続して、最後にエラーを発生させる
- エラーになったメンターの人を記録するので、コードが少し複雑になる
There was a problem hiding this comment.
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にならずにエラー画面が表示されてしまいそう」のような想定をした方がよろしいでしょうか。それとも、別の想定がよろしいでしょうか。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sinsoku
ご連絡遅くなってすみません。
駒形さんにも伺って、今回はrubocopの指摘を優先することとなりました。
とは言え、アドバイスとても勉強になりました。ありがとうございました。🙇♂️
There was a problem hiding this comment.
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の指摘はコメントを使って無効化していただければありがたいです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@komagata
時間がかかりすみません。rubocopに手間取りましたが、無事に修正できたと思います。
ご確認よろしくお願い致します。
3cf4814
to
2b69468
Compare
eb3ed64
to
6c7e7c6
Compare
@komagata |
User.mentor.each do |mentor| | ||
watch = Watch.new( | ||
user: mentor, | ||
watchable: @question | ||
) | ||
watch.save! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 Merge Commitができちゃってるかも? |
44af325
to
14ebae6
Compare
@komagata |
14ebae6
to
fd214e8
Compare
ee5898e
to
33183b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確認しました、OKですー🙆♂️
#2874
機能
どのユーザーが質問を保存しても、メンターさんのみ自動的に「Watch中」になります。
修正点