Question: Best way for integrating data from queries with different sort orders
So I'm looking at returning data from the server with different sort orders - say most recently used vs highest value. The one note that I see about this is from twitter in this Twitter thread wherein FalcorJS suggests including queries as subtrees in the paths e.g. ['titles', 'byField:name', 'where:rating=5'].
So, how would this best be represented in the return jsonGraph? My best guess is that non-canonical (non-id) based returns should be populated with references to the canonical (id) based list? So in the twitter example something like:
{
titlesById: {
"44": {
name: "Nausica in the Valley of the Window",
rating: 5
},
"54": {
name: "The Sound of Music",
rating: 5
}
},
titlesByName: [
'where:rating=5': [
{ $type: "ref", value: ["titlesById", 44] },
{ $type: "ref", value: ["titlesById", 54] }
]
]
};
Is that about right? Is there a better solution?
That's about the way I would do it. I would actually use querystring format, since that's an existing standard.
You can also do some fairly interesting things with $refs - you can have lots of different queries all pointing to the same canonical one. This solves the problem of default parameters or queries coming in out of order:
{
titlesByName: [
// Include a default value
"where[rating]=5": $ref('titlesByName["sort=titleAsc&where[rating]=5"]')
// Enforce alphabetical order
"sort=titleAsc&where[rating]=5": $ref('titlesByName["sort=titleAsc&where[rating]=5"]'),
"sort=titleAsc&where[rating]=5": [
...
]
]
}
This does give a bit of an odd gut feeling, but keep in mind:
- The Router is generating these routes on the fly, just like an HTTP server processes querystrings dynamically instead of having each result hardcoded. It's not going to clutter up your Graph.
- Because these things mostly contain refs to actual objects, they're very small.
- If they do take up a lot of space, Falcor's LRU cache will start to clear out routes you haven't used in a while.
The more I've thought about this pattern, the more I really like it! :grinning:
When you have two different sort orders, presumably two complete arrays must be returned from the server since there's no way to know how many items from the backing data are present in a given page of data for any sort, yeah? There may or may not be a lot of redundant data, but that leaves you with data requests for sortable columns * 2 * filters * pages... which could add up to a lot. Is there any way to ease this load and/or provide a more responsive interface for the user?
I'm currently performing issue triage as we get ready to perform a proper release, and closing/tagging as I go.
See also #775 and #826 for related conversations.
I wouldn't be super worried about the references since they will for the most part be pointing at the real data, with minimal overhead themselves. However, there's always the option of sorting the result yourself based on some criteria once it's provided to you as JSON.