w3c / w3c-api

The W3C API
https://w3c.github.io/w3c-api/
214 stars 92 forks source link

Sort lists of items sensibly before returning them (?) #71

Open tripu opened 7 years ago

tripu commented 7 years ago

How difficult would it be on the API backend [or, would it make sense] to sort lists of items by some relevant field? Right now, some lists are sorted according to some kind of useful order; others look shuffled.

Specifically:

There may be others (I'll add here if I find them).

Most clients I can think of will have to sort those lists themselves anyway. (That's the case with Apiary and Unitas, at least.) Doesn't it make more sense to sort them on the server before returning them?

tripu commented 7 years ago

https://api.w3.org/functions seems ordered by IDs; not numerically but lexicographically.

I suggest order by title instead.

tripu commented 7 years ago

https://api.w3.org/groups/55181/participations?embed=true seems also sorted by numeric ID, but lexicographically (eg, 10 < 9), which is of little use.

jean-gui commented 7 years ago

Actually, there is no sorting at all except for the ones you listed as sorted by family name (which is actually not intentional but comes from a piece of code that does it but shouldn't (IMO)).

My first thought is that sorting should be done client-side, but this is flawed since you couldn't sort paginated results (unless you first retrieved all pages) so I think it is a good idea to add a server-side sorting feature, configurable through the query string. I am not sure how difficult this will be and how long it will take to implement.

tripu commented 7 years ago

I have a vested interest in having human-friendly sorting implemented server-side (for my API clients). But, to be honest, pagination doesn't need friendly sorting — it just needs to be deterministic, predictable.

For example, you could sort everything, always, by the SHA-1 checksum of their primary key, and paginated queries to the API would always return the same results, in the same order. I think that's the only thing that matters to keep consistency on the clients. If a client needs a different order, it should retrieve all pages first, then sort the whole set itself.

That being said… :+1: to sorting sensibly on the server by default, or by passing additional parameters in the request! It'll save me some work! :smile:

jean-gui commented 7 years ago

My apologies, I wasn't clear at all. The way lists are sorted is deterministic, it's just that they are sorted in the order rows were entered in the database. In SQL, if you run "SELECT * from foo;" you will always get results in the same order, it's just usually not any useful order.

tripu commented 7 years ago

@jean-gui: OK, understood. I'll wait for you guys to evaluate this feature request, then.

tripu commented 7 years ago

So, is it on the road map to sort vectors sensibly before serving them, or shall I start implementing that on my clients…?

jean-gui commented 7 years ago

Unfortunately, I don't have time to work on that feature.

tripu commented 7 years ago

Understood, @jean-gui!