diff --git a/ghost/members-importer/lib/importer.js b/ghost/members-importer/lib/importer.js index d0c6a84ea4..29bbb4bbf9 100644 --- a/ghost/members-importer/lib/importer.js +++ b/ghost/members-importer/lib/importer.js @@ -23,9 +23,9 @@ module.exports = class MembersCSVImporter { * @param {({name, at, job, data, offloaded}) => void} options.addJob - Method registering an async job * @param {Object} options.knex - An instance of the Ghost Database connection * @param {Function} options.urlFor - function generating urls - * @param {number} options.importThreshold - threshold to activate freeze flag if reached + * @param {() => Promise} options.fetchThreshold - fetches the threshold to activate freeze flag if reached */ - constructor({storagePath, getTimezone, getMembersApi, sendEmail, isSet, addJob, knex, urlFor, importThreshold}) { + constructor({storagePath, getTimezone, getMembersApi, sendEmail, isSet, addJob, knex, urlFor, fetchThreshold}) { this._storagePath = storagePath; this._getTimezone = getTimezone; this._getMembersApi = getMembersApi; @@ -34,7 +34,7 @@ module.exports = class MembersCSVImporter { this._addJob = addJob; this._knex = knex; this._urlFor = urlFor; - this._importThreshold = importThreshold; + this._fetchThreshold = fetchThreshold; } /** @@ -274,8 +274,9 @@ module.exports = class MembersCSVImporter { meta.originalImportSize = job.batches; - if (this._isSet('checkEmailList') && this._importThreshold) { - meta.freeze = job.batches > this._importThreshold; + if (this._isSet('checkEmailList')) { + const threshold = await this._fetchThreshold(); + meta.freeze = job.batches > threshold; } else { meta.freeze = false; } diff --git a/ghost/members-importer/test/importer.test.js b/ghost/members-importer/test/importer.test.js index 76fd7e605e..fddba7894c 100644 --- a/ghost/members-importer/test/importer.test.js +++ b/ghost/members-importer/test/importer.test.js @@ -73,7 +73,8 @@ describe('Importer', function () { isSet: isSetStub, addJob: sinon.stub(), knex: knexStub, - urlFor: sinon.stub() + urlFor: sinon.stub(), + fetchThreshold: async () => 2 }); const result = await importer.process({ @@ -96,7 +97,7 @@ describe('Importer', function () { should.exist(result.meta.stats.invalid); should.equal(result.meta.import_label, null); - // freeze not triggered if it's not provided + // freeze not triggered if the import is not over the threshold should.exist(result.meta.freeze); result.meta.freeze.should.be.false(); @@ -153,7 +154,7 @@ describe('Importer', function () { addJob: sinon.stub(), knex: knexStub, urlFor: sinon.stub(), - importThreshold: 1 + fetchThreshold: async () => 1 }); const result = await importer.process({