lavab / api

Lavaboom's main backend API.
https://lavaboom.com
23 stars 11 forks source link

Apply Jorge's example query to other select-intensive RethinkDB queries #145

Closed pzduniak closed 9 years ago

pzduniak commented 9 years ago
r
.table('labels')
.getAll(owner, { index: 'owner' })
.map(function (label) {
    return r.table('threads')
        .getAll(label('id'), { index: 'labels'})
        .coerceTo('array')
        .do(function (threads) {
            return label.merge({
                'total_threads_count': threads.count(),
                'unread_threads_count': threads.filter(function (thread) {
                    return thread('is_read').not().and(
                        thread('labels').contains(function (label) {
                          return r.expr(spamTrashSent)
                            .map(function (row) { return row('id'); })
                            .contains(label);
                        }).not()
                    )
                }).count()
            });
        });
});