Released memory in importer as early as possible

no issue

- set bigger objects to null as soon as possible
- this will trigger the GC to free memory
This commit is contained in:
kirrg001 2018-08-12 12:22:23 +02:00
parent d421b8ccac
commit 3ed5087deb
3 changed files with 16 additions and 43 deletions

View File

@ -301,7 +301,7 @@ class Base {
let ops = [];
_.each(this.dataToImport, (obj) => {
_.each(this.dataToImport, (obj, index) => {
ops.push(() => {
return models[this.modelName].add(obj, options)
.then((importedModel) => {
@ -321,7 +321,8 @@ class Base {
email: importedModel.get('email')
});
return importedModel;
importedModel = null;
this.dataToImport.splice(index, 1);
})
.catch((err) => {
return this.handleError(err, obj);
@ -337,7 +338,11 @@ class Base {
*
* Promise.map(.., {concurrency: Int}) was not really improving the end performance for me.
*/
return sequence(ops);
return sequence(ops).then((response) => {
this.dataToImport = null;
ops = null;
return response;
});
}
}

View File

@ -125,6 +125,11 @@ DataImporter = {
return toReturn;
}).catch(function (errors) {
return Promise.reject(errors);
}).finally(() => {
// release memory
importers = {};
results = null;
importData = null;
});
}
};

View File

@ -1001,44 +1001,7 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
User: 'users',
Tag: 'tags'
};
const reducedFields = options.reducedFields;
const exclude = {
Post: [
'title',
'mobiledoc',
'html',
'plaintext',
'amp',
'codeinjection_head',
'codeinjection_foot',
'meta_title',
'meta_description',
'custom_excerpt',
'og_image',
'og_title',
'og_description',
'twitter_image',
'twitter_title',
'twitter_description',
'custom_template'
],
User: [
'bio',
'website',
'location',
'facebook',
'twitter',
'accessibility',
'meta_title',
'meta_description',
'tour'
],
Tag: [
'description',
'meta_title',
'meta_description'
]
};
const exclude = options.exclude;
const filter = options.filter;
const withRelated = options.withRelated;
const withRelatedFields = options.withRelatedFields;
@ -1080,10 +1043,10 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
}
// exclude fields if enabled
if (reducedFields) {
if (exclude) {
const toSelect = _.keys(schema.tables[tableNames[modelName]]);
_.each(exclude[modelName], (key) => {
_.each(exclude, (key) => {
if (toSelect.indexOf(key) !== -1) {
toSelect.splice(toSelect.indexOf(key), 1);
}