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

Made Setting for test,and merged before branch main #7

Merged
merged 18 commits into from
Oct 7, 2024

Conversation

taku072002T
Copy link
Collaborator

@taku072002T taku072002T commented Jul 20, 2024

受講生の確認事項

  • 画面をブラウザで実際に開いてテスト要件の画面と機能の動作確認をした(動作が分からない場合講師からスクリーンショットの提出を求めることがあります)
  • 作成したモデルを全てDjango管理画面に登録した
  • テスト要件のテストを全て実装した
  • CI が全て通った

1次レビュアーの確認事項

Copy link

@HasegawaKota HasegawaKota left a comment

Choose a reason for hiding this comment

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

以下の点を直してみてください!
①今回のいいね機能の実装では非同期通信で実装する必要があるため、Ajax の FetchAPI(JavaScriptのなんか)を使ってください!

②いいね機能の実装範囲とは違ってしまうのですが、ホーム画面において他者のプロフィールのリンクを貼ってください。今のままだとURLをいじらないとアクセスしたい相手のプロフィールに飛ぶことが出来ないので...

Copy link

flake8(linter)のチェックに失敗しました。CI実行のログを確認して修正し,再度コミット・プッシュしてください。

@taku072002T
Copy link
Collaborator Author

ご指摘点、修正しました!
再レビューよろしくお願いします!

Copy link

@IzmYuta IzmYuta left a comment

Choose a reason for hiding this comment

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

よく書けていると思います!
ただ、何ヶ所か疑問に思った部分があったので返信or修正お願いします!

@@ -15,3 +15,18 @@ class Tweet(models.Model):

content = models.CharField(max_length=100)
created_at = models.DateTimeField(default=timezone.now)


class Favorite(models.Model):
Copy link

Choose a reason for hiding this comment

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

ViewではLike・Unlikeとしている一方で、ModelではFavoriteと命名した理由は何ですか?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

参考記事に引っ張られた命名になっていたと思います。

tweets/tests.py Outdated Show resolved Hide resolved
tweets/views.py Outdated
i = 0
for tweet in tweets_list:
tweet.n_liked = Favorite.objects.filter(tweet=tweet).all().count()
tweet.number = i + 1
Copy link

Choose a reason for hiding this comment

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

tweet.numberは何のための数値ですか?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tweet.numberは、tweets/home.htmlにおいて、Ajax操作を行う時、それぞれのツイートに対して別々のタグを振り分けるためのIDとして扱っています。

tweets/views.py Outdated Show resolved Hide resolved
tweets/views.py Outdated
except Tweet.DoesNotExist:
return HttpResponseNotFound("Tweet does not exist")
else:
_, created = Favorite.objects.get_or_create(user=user, tweet=tweet)
Copy link

Choose a reason for hiding this comment

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

createdは使われていますか?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

createdは使われていません。
これは、もともと Favoriteが作られたか作られていないかで動作を分けていたのですが、
よくよく考えてみたらその動作は必要なく、その名残がそのまま残っていたものでした。
次のコミットでは、フラグの代入部分を消し、等式の右側のみが残る形になると思います。

@@ -63,6 +65,15 @@ def get_context_data(self):
def userprofile_view(request, username):
user = User.objects.get(username=username)
tweets_list = Tweet.objects.select_related("user").filter(user=user)
i = 0
for tweet in tweets_list:
if Favorite.objects.filter(user=request.user, tweet=tweet).exists():
Copy link

Choose a reason for hiding this comment

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

for文内でのDB操作は極力避けましょう(N+1問題)
request.userがいいねをしたツイートIDを取得することは、for文外でも可能だと思います。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

N+1問題がたくさん...
こちらも次のコミットで改修します!

tweet.liked = True
else:
tweet.liked = False
tweet.n_liked = Favorite.objects.filter(tweet=tweet).all().count()
Copy link

Choose a reason for hiding this comment

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

いいね数も同様です。

tweets/views.py Outdated
Comment on lines 18 to 27
i = 0
for tweet in tweets_list:
tweet.n_liked = Favorite.objects.filter(tweet=tweet).all().count()
tweet.number = i + 1
i += 1
if Favorite.objects.filter(user=request.user, tweet=tweet).exists():
tweet.liked = True
else:
tweet.liked = False
tweets_number = tweets_list.count()
Copy link

Choose a reason for hiding this comment

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

N+1問題。

Copy link

Django設定のチェックに失敗しました。CI実行のログを確認して修正し,再度コミット・プッシュしてください。

Copy link

マイグレーションファイルとコードに差分があります。migrationを生成し,再度コミット・プッシュしてください。詳細

Copy link

Django設定のチェックに失敗しました。CI実行のログを確認して修正し,再度コミット・プッシュしてください。

Copy link

マイグレーションファイルとコードに差分があります。migrationを生成し,再度コミット・プッシュしてください。詳細

Copy link

Django設定のチェックに失敗しました。CI実行のログを確認して修正し,再度コミット・プッシュしてください。

Copy link

マイグレーションファイルとコードに差分があります。migrationを生成し,再度コミット・プッシュしてください。詳細

Copy link

マイグレーションファイルとコードに差分があります。migrationを生成し,再度コミット・プッシュしてください。詳細

Copy link

Django設定のチェックに失敗しました。CI実行のログを確認して修正し,再度コミット・プッシュしてください。

Copy link

github-actions bot commented Oct 6, 2024

マイグレーションファイルとコードに差分があります。migrationを生成し,再度コミット・プッシュしてください。詳細

Copy link

github-actions bot commented Oct 6, 2024

Django設定のチェックに失敗しました。CI実行のログを確認して修正し,再度コミット・プッシュしてください。

Copy link

@IzmYuta IzmYuta left a comment

Choose a reason for hiding this comment

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

LGTM

@taku072002T
Copy link
Collaborator Author

レビューありがとうございました!
初めて触れたコードが多くあり、良い経験になったと思います!
重ねてレビュアーの方々に感謝します!

@taku072002T taku072002T merged commit 809342f into main Oct 7, 2024
2 checks passed
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.

3 participants