Last active
August 29, 2015 13:57
-
-
Save marshall007/9867115 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# before | |
r.table('replications') | |
.getAll(lab_id, index: 'lab_id') | |
.groupedMapReduce( | |
r.row('source_id'), | |
r.row.pluck('id', 'created'), | |
(acc, row) -> | |
r.branch acc('created').gt(row('created')), acc, row | |
) | |
# after | |
r.table('replications') | |
.getAll(lab_id, index: 'lab_id') | |
.group('source_id') | |
.max('created') | |
#### | |
# before | |
Replications.by_test = (base_query, options) -> | |
query = base_query | |
.groupedMapReduce( | |
r.row('test_id'), | |
(row) -> | |
[ row 'id' ] | |
(acc, row) -> | |
acc.union row | |
) | |
rql(query.concatMap r.row 'reduction').then (ids) -> | |
return When.resolve [] if ids.length is 0 | |
query = r.table('replication_results') | |
query = query.getAll.apply(query, ids) | |
.pluck('source_id', 'replication_id', 'test_id', 'url', 'data') | |
.coerceTo 'array' | |
return rql query | |
# after | |
Replications.by_test = (base_query, options) -> | |
query = base_query | |
.group('test_id') | |
.pluck('source_id', 'replication_id', 'test_id', 'url', 'data') | |
.ungroup() | |
return rql query.concatMap r.row('reduction') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment