[FIX] Anonymous users are counted on the server statistics and engagement dashboard (#19263)
Co-authored-by: Diego Sampaio <chinello@gmail.com>pull/19358/head
parent
0522de4b17
commit
368a3624cd
@ -0,0 +1,41 @@ |
||||
import Future from 'fibers/future'; |
||||
|
||||
import { Migrations } from '../../../app/migrations'; |
||||
import { Users, Sessions } from '../../../app/models/server/raw'; |
||||
|
||||
async function migrateSessions(fut) { |
||||
const cursor = Users.find({ roles: 'anonymous' }, { projection: { _id: 1 } }); |
||||
if (!cursor) { |
||||
return; |
||||
} |
||||
|
||||
|
||||
const users = await cursor.toArray(); |
||||
if (users.length === 0) { |
||||
fut.return(); |
||||
return; |
||||
} |
||||
|
||||
const userIds = users.map(({ _id }) => _id); |
||||
|
||||
Sessions.update({ |
||||
userId: { $in: userIds }, |
||||
}, { |
||||
$set: { |
||||
roles: ['anonymous'], |
||||
}, |
||||
}, { |
||||
multi: true, |
||||
}); |
||||
|
||||
fut.return(); |
||||
} |
||||
|
||||
Migrations.add({ |
||||
version: 208, |
||||
up() { |
||||
const fut = new Future(); |
||||
migrateSessions(fut); |
||||
fut.wait(); |
||||
}, |
||||
}); |
Loading…
Reference in new issue