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

feat(opinion): Add ordering key #4496

Merged
merged 15 commits into from
Dec 17, 2024
Merged

feat(opinion): Add ordering key #4496

merged 15 commits into from
Dec 17, 2024

Conversation

flooie
Copy link
Contributor

@flooie flooie commented Sep 25, 2024

Add ordering key to Opinion class meta field for sub opinions

Postgres requires ordering for distinct columns
and since ordering_key is one we need to sort by
cluster and ordering key before we can distinct
@flooie flooie requested review from ERosendo and mlissner and removed request for ERosendo September 26, 2024 17:35
cl/search/models.py Outdated Show resolved Hide resolved
@flooie flooie assigned quevon24 and unassigned flooie Dec 2, 2024
remove unnecessary migrations
set opinions ordering in OpinionClusterViewSet
display opinions in the correct order in the old opinions template (remove ordering by type)
@quevon24
Copy link
Member

quevon24 commented Dec 5, 2024

This is the list of changes:

  • Remove default ordering in Opinion model
  • Remove unnecessary migrations
  • Set opinions ordering in OpinionClusterViewSet (opinions displayed in correct order in API)
  • Display opinions in the correct order in the old opinions template (remove ordering by type)

@quevon24 quevon24 assigned flooie and unassigned quevon24 Dec 5, 2024
@grossir grossir self-requested a review December 13, 2024 16:34
@flooie flooie assigned grossir and unassigned flooie Dec 13, 2024
@grossir
Copy link
Contributor

grossir commented Dec 13, 2024

While testing this I noticed a related ordering problems, in the search results page; we may want to turn this into a separate issue
image

OpinionCluster.objects.prefetch_related(
Prefetch(
"sub_opinions",
queryset=Opinion.objects.order_by("ordering_key"),
Copy link
Contributor

Choose a reason for hiding this comment

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

About the case when there are opinions with both NULL and valid ordering_key values, it will not show the "Combined" or scraped opinion first
image

However, if you change

from django.db.models import F
...
queryset=Opinion.objects.order_by(F("ordering_key").asc(nulls_first=True))

it will use the desired order
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @grossir

@grossir grossir removed their assignment Dec 16, 2024
@flooie flooie enabled auto-merge December 17, 2024 21:29
@flooie flooie merged commit 9951ee8 into main Dec 17, 2024
15 checks passed
@flooie flooie deleted the add-ordering-key branch December 17, 2024 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants