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

Add coalesce for release date sort for favorites query #3836

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions discovery-provider/src/queries/get_save_tracks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional, TypedDict

from sqlalchemy import asc, desc, or_
from sqlalchemy import asc, desc, or_, func
from sqlalchemy.sql.functions import coalesce
from src.models.social.aggregate_plays import AggregatePlay
from src.models.social.save import Save, SaveType
from src.models.tracks.aggregate_track import AggregateTrack
Expand Down Expand Up @@ -84,7 +85,16 @@ def get_save_tracks(args: GetSaveTracksArgs):
elif sort_method == SortMethod.artist_name:
base_query = base_query.order_by(sort_fn(TrackWithAggregates.user.name))
elif sort_method == SortMethod.release_date:
base_query = base_query.order_by(sort_fn(TrackWithAggregates.release_date))
base_query = base_query.order_by(
sort_fn(
coalesce(
func.to_date_safe(
TrackWithAggregates.release_date, "Dy Mon DD YYYY HH24:MI:SS"
),
TrackWithAggregates.created_at,
)
)
)
elif sort_method == SortMethod.added_date:
base_query = base_query.order_by(
sort_fn(Save.created_at), desc(TrackWithAggregates.track_id)
Expand Down