From 0cf6dbd2b6e66fb3bc2b81ee6b1763bcf0306167 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 26 Mar 2020 02:13:16 -0300 Subject: [PATCH] Group DM improvements --- .../client/views/app/CreateDirectMessage.js | 3 +++ server/startup/migrations/v179.js | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/ui/client/views/app/CreateDirectMessage.js b/app/ui/client/views/app/CreateDirectMessage.js index 667a4e63d49..3370559e102 100755 --- a/app/ui/client/views/app/CreateDirectMessage.js +++ b/app/ui/client/views/app/CreateDirectMessage.js @@ -1,6 +1,7 @@ import { Tracker } from 'meteor/tracker'; import { Meteor } from 'meteor/meteor'; import { Template } from 'meteor/templating'; +import { ReactiveVar } from 'meteor/reactive-var'; import { roomTypes } from '../../../../utils/client'; import { call } from '../../../../ui-utils/client'; @@ -83,6 +84,8 @@ Template.CreateDirectMessage.onRendered(function() { }); Template.CreateDirectMessage.onCreated(function() { + this.selectedUsers = new ReactiveVar([]); + this.onSelectUser = ({ item: user }) => { if (user.username === Meteor.user().username) { return; diff --git a/server/startup/migrations/v179.js b/server/startup/migrations/v179.js index a7e4d81a3b6..cf275527edd 100644 --- a/server/startup/migrations/v179.js +++ b/server/startup/migrations/v179.js @@ -41,13 +41,22 @@ async function migrateDMs(models, total, current) { const items = await roomCollection.find({ t: 'd', uids: { $exists: false } }, { fields: { _id: 1 } }).limit(batchSize).toArray(); - const actions = items.map((room) => roomCollection.updateOne({ _id: room._id }, { - $set: { - uids: getIds(room._id), + const actions = items.map((room) => ({ + updateOne: { + filter: { _id: room._id }, + update: { + $set: { + uids: getIds(room._id), + }, + }, }, })); - const batch = Promise.all(actions); + if (actions.length === 0) { + return; + } + + const batch = await roomCollection.bulkWrite(actions, { ordered: false }); if (actions.length === batchSize) { await batch; return migrateDMs(models, total, current + batchSize); @@ -68,7 +77,7 @@ Migrations.add({ const total = await rooms.count(); await rooms.close(); - if (total < batchSize * 2) { + if (total < batchSize * 10) { await migrateDMs({ roomCollection }, total, 0); return fut.return(); }