Skip to content

Commit

Permalink
optimized groups.listAll
Browse files Browse the repository at this point in the history
  • Loading branch information
ostjen committed Aug 16, 2021
1 parent f7e229e commit 42ddd9a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions app/api/server/v1/groups.js
Expand Up @@ -481,15 +481,21 @@ API.v1.addRoute('groups.listAll', { authRequired: true }, {
const { sort, fields, query } = this.parseJsonQuery();
const ourQuery = Object.assign({}, query, { t: 'p' });

let rooms = Rooms.find(ourQuery).fetch();
const totalCount = rooms.length;

rooms = Rooms.processQueryOptionsOnResult(rooms, {
const cursor = Rooms.find(ourQuery, {
sort: sort || { name: 1 },
skip: offset,
limit: count,
fields,
});
fields })

const totalCount = cursor.count();
const rooms = cursor.fetch();

// rooms = Rooms.processQueryOptionsOnResult(rooms, {
// sort: sort || { name: 1 },
// skip: offset,
// limit: count,
// fields,
// });

return API.v1.success({
groups: rooms.map((room) => this.composeRoomWithLastMessage(room, this.userId)),
Expand Down

0 comments on commit 42ddd9a

Please sign in to comment.