artsy / bearden

A simple database of organizations
MIT License
3 stars 8 forks source link

Sort rankables by lowest rank first, then newest first, more explicitly. #321

Closed dblock closed 7 years ago

dblock commented 7 years ago

See https://github.com/artsy/bearden/pull/317#discussion_r144834710, just like @yuki24 said, sorting in the database, then outside is ignoring sorting in the database.

Consolidating ranking into OrganizationResolver.

What we want is to sort by rank (lowest rank first), then by time (newest first).

jonallured commented 7 years ago

Yeah, the rules here are lowest rank is best and then rank ties go to the newest data. Consider the case where a gallery changes name. If we have a source that changes the name it reports, then we'd have data like this:

{ name: 'Busted Gallery', rank: 1, created_at: 1.year.ago }
{ name: 'Sparkle Gallery', rank: 1, created_at: 1.month.ago }
{ name: 'Dusted Gallery', rank: 2, created_at: 1.week.ago }

What we want is for Sparkle Gallery to be returned because it has the lowest rank and is the newest data. At this point I don't really care how the remaining records are sorted, but I would assume an order like this:

[
  { name: 'Sparkle Gallery', rank: 1, created_at: 1.month.ago },
  { name: 'Busted Gallery', rank: 1, created_at: 1.year.ago },
  { name: 'Dusted Gallery', rank: 2, created_at: 1.week.ago }
]

Sort first by rank, lowest first; then by created_at, newest first.

dblock commented 7 years ago

@jonallured This is updated and ready to merge.

jonallured commented 7 years ago

Awesome, thank yous all around!! 🤗