remove user data when not needed

This commit is contained in:
Ramón Souza 2022-02-02 13:53:23 +00:00
parent 457175dbba
commit c5e9b3a02f
5 changed files with 37 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import ConnectionStatus from '/imports/api/connection-status';
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import changeHasConnectionStatus from '/imports/api/users-persistent-data/server/modifiers/changeHasConnectionStatus';
export default function updateConnectionStatus(meetingId, userId, level) {
check(meetingId, String);
@ -24,6 +25,7 @@ export default function updateConnectionStatus(meetingId, userId, level) {
const { numberAffected } = ConnectionStatus.upsert(selector, modifier);
if (numberAffected) {
changeHasConnectionStatus(true, userId, meetingId);
Logger.verbose(`Updated connection status meetingId=${meetingId} userId=${userId} level=${level}`);
}
} catch (err) {

View File

@ -0,0 +1,25 @@
import Logger from '/imports/startup/server/logger';
import UsersPersistentData from '/imports/api/users-persistent-data';
export default function changeHasConnectionStatus(hasConnectionStatus, userId, meetingId) {
const selector = {
meetingId,
userId,
};
const modifier = {
$set: {
'shouldPersist.hasConnectionStatus': hasConnectionStatus,
},
};
try {
const numberAffected = UsersPersistentData.update(selector, modifier);
if (numberAffected) {
Logger.info(`Changed hasConnectionStatus=${hasConnectionStatus} id=${userId} meeting=${meetingId}`);
}
} catch (err) {
Logger.error(`Change hasConnectionStatus error: ${err}`);
}
}

View File

@ -9,7 +9,7 @@ export default function changeHasMessages(hasMessages, userId, meetingId) {
const modifier = {
$set: {
hasMessages,
'shouldPersist.hasMessages': hasMessages,
},
};

View File

@ -27,7 +27,7 @@ function usersPersistentData() {
meetingId,
$or: [
{
hasMessages: true,
'shouldPersist.hasMessages': true,
},
{
loggedOut: false,

View File

@ -5,6 +5,7 @@ import Logger from '/imports/startup/server/logger';
import setloggedOutStatus from '/imports/api/users-persistent-data/server/modifiers/setloggedOutStatus';
import clearUserInfoForRequester from '/imports/api/users-infos/server/modifiers/clearUserInfoForRequester';
import ClientConnections from '/imports/startup/server/ClientConnections';
import UsersPersistentData from '/imports/api/users-persistent-data';
import VoiceUsers from '/imports/api/voice-users/';
const clearAllSessions = (sessionUserId) => {
@ -36,7 +37,13 @@ export default function removeUser(meetingId, userId) {
clearUserInfoForRequester(meetingId, userId);
const currentUser = UsersPersistentData.findOne({ userId, meetingId });
const hasMessages = currentUser?.shouldPersist?.hasMessages;
const hasConnectionStatus = currentUser?.shouldPersist?.hasConnectionStatus;
if (!hasMessages && !hasConnectionStatus) {
UsersPersistentData.remove(selector);
}
Users.remove(selector);
VoiceUsers.remove({ intId: userId, meetingId });
}