Skip to content

Conversation

nacchan99
Copy link
Contributor

@nacchan99 nacchan99 commented Jul 31, 2025

Fixes. #1716
cf. #1704 (cf. #1577

lib/tasks/fetch_news.rake

解決すべき問題

  • ネストが深く読みづらい問題
  • 常に全ての既存アイテムが更新されてしまう問題
    • fetch_news.rake → 差分がある場合のみ更新するように修正
      ↪︎ title または published_at に差分がある場合だけ updated_items に追加
    • import_news.rake → 更新があった場合のみ save!
      ↪︎ news.changed? で変更があるか判定。
      新規 or 変更時だけ保存(既存データはそのまま)。
      (ログに新規/更新のステータスも出力)

@nacchan99 nacchan99 changed the title [WIP]Rakeタスクのリファクタリング Rakeタスクのリファクタリング Jul 31, 2025
end

puts "Imported #{entries.size} items."
puts "Imported #{new_count + updated_count} items (#{new_count} new, #{updated_count} updated)."
Copy link
Contributor

Choose a reason for hiding this comment

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

提案なので更新はお任せしますが、fetch_news.rake と同様に logger で出力する方法に揃えてあげても良さそうです📝
(出力の内容は良さそうです🙆‍♀️)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ありがとうございます!🙌
確かに logger 出力に揃えた方がスッキリすると思うので、fetch_news.rake と同様の logger 設定に変更します✨

Copy link
Contributor

@rakuda-san-desu rakuda-san-desu left a comment

Choose a reason for hiding this comment

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

タスク実行時の更新状況も、よりわかりやすくなりました🙆‍♀️
1件コメントしていますが、このままでも問題ないと思うのでApproveしています。

対応ありがとうございます🙏✨

@nacchan99
Copy link
Contributor Author

@rakuda-san-desu 何度もすみません🙏
お手隙の際に最終確認をお願いします✨

Copy link
Contributor

@rakuda-san-desu rakuda-san-desu left a comment

Choose a reason for hiding this comment

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

対応ありがとうございます!
ログの出力も確認しました🙆‍♀️

1件コメントしましたが、それ以外は良さそうです。
対応後、マージしていただければ🙏✨

new_count += 1 if is_new
updated_count += 1 unless is_new

logger.info "[News] #{news.published_at.to_date} #{news.title} (#{status})" # ← puts から logger.info に変更
Copy link
Contributor

Choose a reason for hiding this comment

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

この部分のコメントは不要そうです✂️

それ以外は良さそうです!
対応ありがとうございます👍

@nacchan99
Copy link
Contributor Author

修正対応全て完了し、テストもパスしたのでマージします🚀

@nacchan99 nacchan99 merged commit 088d081 into main Aug 5, 2025
4 checks passed
@nacchan99 nacchan99 deleted the refactor/rake_tasks_1716 branch August 5, 2025 06:50
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.

2 participants