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

[Forum] Display who upvoted/downvoted each post. Closes #346 #423

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

stopnoanime
Copy link
Contributor

@stopnoanime stopnoanime commented Nov 19, 2024

Displays usernames of users who upvoted/downvoted each post in a tooltip.
Only 10 usernames for each post are queried and displayed to improve performance.
I'm using prefetch_related to query necessary reactions for all posts with a single query.

Translation for a single string needs to be added, but afaik I can only do that in Transifex after this is merged?

@stopnoanime stopnoanime linked an issue Nov 19, 2024 that may be closed by this pull request
@stopnoanime stopnoanime marked this pull request as ready for review November 28, 2024 18:23
@stopnoanime stopnoanime marked this pull request as draft December 2, 2024 16:26
@stopnoanime
Copy link
Contributor Author

This PR has a bug that causes the latest posts view to not load. I turned the PR to a draft while I investigate why the tests didn't detect this.

@stopnoanime
Copy link
Contributor Author

Added a test that checks the latest post view with reactions enabled.
Added two dictionaries that map reactions to necessary attribute names so the code doesn't rely on string manipulations anymore. Also moved prefetching reacted_by into the Post model so there is no need to call a separate function to do so.

@stopnoanime stopnoanime marked this pull request as ready for review December 5, 2024 17:40
Copy link
Contributor

@twalen twalen left a comment

Choose a reason for hiding this comment

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

Looks ok, but please add ordering + modify tests

models.Prefetch(
'reactions',
to_attr=attr_name,
queryset=PostReaction.objects.filter(type_of_reaction=rtype).select_related('author')[:max_count],
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be nice to add some ordering here, otherwise we can get random results (especially important during tests): i.e. order_by('-pk')

also you can add Meta class to PostReaction like:

class Meta:
        ordering = ['-pk']

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.

[Forum] Display who upvoted/downvoted each post
2 participants