Remove memory leak from userData (#22094)

Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz>
pull/22101/head
Gabriel Thomé 4 years ago committed by GitHub
parent 0d081438d2
commit 3079c9b91c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/notifications/client/lib/Notifications.js
  2. 6
      app/ui-sidenav/client/userPresence.js
  3. 5
      client/lib/userData.ts
  4. 1
      client/startup/startup.ts

@ -75,8 +75,9 @@ class Notifications {
return this.streamRoom.on(`${ room }/${ eventName }`, callback);
}
onUser(eventName, callback) {
return this.streamUser.on(`${ Meteor.userId() }/${ eventName }`, callback);
async onUser(eventName, callback) {
await this.streamUser.on(`${ Meteor.userId() }/${ eventName }`, callback);
return () => this.unUser(eventName, callback);
}
unAll(callback) {

@ -73,18 +73,14 @@ const featureExists = !!window.IntersectionObserver;
const observer = featureExists && new IntersectionObserver(handleEntries, options);
let wasConnected = Meteor.status().connected;
Tracker.autorun(() => {
// Only clear statuses on disconnect, prevent process it on reconnect again
const isConnected = Meteor.status().connected;
if (!Meteor.userId() || (wasConnected && !isConnected)) {
wasConnected = isConnected;
if (!Meteor.userId() || !isConnected) {
Presence.reset();
return Meteor.users.update({ status: { $exists: true } }, { $unset: { status: true } }, { multi: true });
}
mem.clear(get);
wasConnected = isConnected;
Presence.restart();

@ -27,12 +27,15 @@ const updateUser = (userData: IUser & { _updatedAt: Date }): void => {
Meteor.users.update({ _id: user._id }, { $set: userData });
};
let cancel: undefined | (() => void);
export const synchronizeUserData = async (uid: Meteor.User['_id']): Promise<RawUserData | void> => {
if (!uid) {
return;
}
Notifications.onUser('userData', (data: IUserDataEvent) => {
cancel && cancel();
cancel = await Notifications.onUser('userData', (data: IUserDataEvent) => {
switch (data.type) {
case 'inserted':
// eslint-disable-next-line @typescript-eslint/no-unused-vars

@ -47,6 +47,7 @@ Meteor.startup(() => {
}
const user = await synchronizeUserData(uid);
if (!user) {
return;
}

Loading…
Cancel
Save