c# - Querying Parse class to get top N objects sorted by certain field from groups of objects matched by another field? -


sorry if answered here or on docs before, did search hadn't encountered answer yet. i'm using unity parse sdk. idea gets bit verbose when describe straight on, i'll start illustration. imagine simple leaderboard divided several activities , displaying n top times per activity:

leaderboard illustration

let's have set of result objects stored in parse db, containing activityid , time fields (and fluff fields user names, irrelevant). want set query return only, say, 5 result objects per activityid, smallest time across activityid , sorted time. if follow ui mockup above, desired array i'd query potentially this:

0  | activityid: 0 | time: 43 1  | activityid: 0 | time: 72 2  | activityid: 0 | time: 81 3  | activityid: 0 | time: 92 4  | activityid: 0 | time: 97 5  | activityid: 1 | time: 12 6  | activityid: 1 | time: 42  ...  13 | activityid: 2 | time: 49 14 | activityid: 2 | time: 52 

after studying related docs, stumbling block me not knowing how limit queries in other way this:

query = query.limit (n); 

ideally, want split results in parse db separate groups activityid value, , perform sorting time on groups, , perform trimming n, , return query response consisting of (n * number of activity types) objects. linq, result following expression:

leaderboardresults.groupby(x => activityid).selectmany(x => x.orderby(x => x.time).take(n)); 

except have use parse methods , syntax, , i'm not sure how same result them. undesirable request mentioned in bottom right of illustration can formulated this:

var query = parseobject.getquery ("result").orderby ("activityid").thenby ("time"); var querytask = query.findasync ().continuewith (t => {     ienumerable<parseobject> results = t.result;     // stuff query results } 

this dump every single result in existence client, not okay. using query.limit (n) mentioned above not right either, dump every single result first , subsequent activities until object count limit runs out, while want @ least object count returned per activity.

obviously, it's possible issue multiple requests separate per-activity arrays of results on client side, can imagine that's horrifying solution in terms of backend load , in terms of client performance. ideally need 1 query returning array of (leaderboard size * activity type count) sorted objects.

so how can achieve this? feel i'm missing simple piece of puzzle.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -