Fix possible memory leak in inner and worker

pull/1/head
yflory 4 years ago
parent 7f44009617
commit c43c1a447d

@ -972,6 +972,19 @@ define([
require(['/api/broadcast?'+ (+new Date())], function (Broadcast) { require(['/api/broadcast?'+ (+new Date())], function (Broadcast) {
// XXX require.s.contexts._ can be used to erase old loaded objects // XXX require.s.contexts._ can be used to erase old loaded objects
cb(Broadcast); cb(Broadcast);
setTimeout(function () {
try {
var ctx = require.s.contexts._;
var defined = ctx.defined;
Object.keys(defined).forEach(function (href) {
if (/^\/api\/broadcast\?[0-9]{13}/.test(href)) {
console.error(href);
delete defined[href];
return;
}
});
} catch (e) {}
});
}); });
}; };
}; };
@ -1061,7 +1074,7 @@ define([
var form = h('div.cp-admin-broadcast-form'); var form = h('div.cp-admin-broadcast-form');
var $form = $(form).appendTo($div); var $form = $(form).appendTo($div);
var refresh = getApi(function (/* Broadcast */) { // XXX unused argument var refresh = getApi(function (Broadcast) {
var button = h('button.btn.btn-primary', Messages.admin_broadcastButton); var button = h('button.btn.btn-primary', Messages.admin_broadcastButton);
var $button = $(button); var $button = $(button);
var removeButton = h('button.btn.btn-danger', Messages.admin_broadcastCancel); var removeButton = h('button.btn.btn-danger', Messages.admin_broadcastCancel);
@ -1071,8 +1084,7 @@ define([
var deleted = []; var deleted = [];
// Render active message (if there is one) // Render active message (if there is one)
require(['/api/broadcast?'+ (+new Date())], function (BCast) { var hash = Broadcast.lastBroadcastHash || '1'; // Truthy value if no lastKnownHash
var hash = BCast.lastBroadcastHash || '1'; // Truthy value if no lastKnownHash
common.mailbox.getNotificationsHistory('broadcast', null, hash, function (e, msgs) { common.mailbox.getNotificationsHistory('broadcast', null, hash, function (e, msgs) {
if (e) { return void console.error(e); } if (e) { return void console.error(e); }
if (!Array.isArray(msgs)) { return; } if (!Array.isArray(msgs)) { return; }
@ -1109,7 +1121,6 @@ define([
}); });
if (!activeUid) { $active.hide(); } if (!activeUid) { $active.hide(); }
}); });
});
// Custom message // Custom message
var container = h('div.cp-broadcast-container'); var container = h('div.cp-broadcast-container');

@ -630,6 +630,7 @@ define([
// use uid in /api/broadcast so that all connected users will use the same cached // use uid in /api/broadcast so that all connected users will use the same cached
// version on the server // version on the server
require(['/api/broadcast?'+uid], function (Broadcast) { require(['/api/broadcast?'+uid], function (Broadcast) {
if (!Broadcast) { return; }
broadcast([], 'UNIVERSAL_EVENT', { broadcast([], 'UNIVERSAL_EVENT', {
type: 'broadcast', type: 'broadcast',
data: { data: {
@ -637,6 +638,18 @@ define([
data: Broadcast.maintenance data: Broadcast.maintenance
} }
}); });
setTimeout(function () {
try {
var ctx = require.s.contexts._;
var defined = ctx.defined;
Object.keys(defined).forEach(function (href) {
if (/^\/api\/broadcast\?[a-z0-9]+/.test(href)) {
delete defined[href];
return;
}
});
} catch (e) {}
});
}); });
}; };
Store.onSurveyUpdate = function (uid) { Store.onSurveyUpdate = function (uid) {

Loading…
Cancel
Save