0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

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 = []; let ops = [];
_.each(this.dataToImport, (obj) => { _.each(this.dataToImport, (obj, index) => {
ops.push(() => { ops.push(() => {
return models[this.modelName].add(obj, options) return models[this.modelName].add(obj, options)
.then((importedModel) => { .then((importedModel) => {
@ -321,7 +321,8 @@ class Base {
email: importedModel.get('email') email: importedModel.get('email')
}); });
return importedModel; importedModel = null;
this.dataToImport.splice(index, 1);
}) })
.catch((err) => { .catch((err) => {
return this.handleError(err, obj); return this.handleError(err, obj);
@ -337,7 +338,11 @@ class Base {
* *
* Promise.map(.., {concurrency: Int}) was not really improving the end performance for me. * 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; return toReturn;
}).catch(function (errors) { }).catch(function (errors) {
return Promise.reject(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', User: 'users',
Tag: 'tags' Tag: 'tags'
}; };
const reducedFields = options.reducedFields; const exclude = options.exclude;
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 filter = options.filter; const filter = options.filter;
const withRelated = options.withRelated; const withRelated = options.withRelated;
const withRelatedFields = options.withRelatedFields; const withRelatedFields = options.withRelatedFields;
@ -1080,10 +1043,10 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
} }
// exclude fields if enabled // exclude fields if enabled
if (reducedFields) { if (exclude) {
const toSelect = _.keys(schema.tables[tableNames[modelName]]); const toSelect = _.keys(schema.tables[tableNames[modelName]]);
_.each(exclude[modelName], (key) => { _.each(exclude, (key) => {
if (toSelect.indexOf(key) !== -1) { if (toSelect.indexOf(key) !== -1) {
toSelect.splice(toSelect.indexOf(key), 1); toSelect.splice(toSelect.indexOf(key), 1);
} }