Skip to content

Instantly share code, notes, and snippets.

@marshall007
Last active August 29, 2015 13:57
Show Gist options
  • Save marshall007/9867115 to your computer and use it in GitHub Desktop.
Save marshall007/9867115 to your computer and use it in GitHub Desktop.
# 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