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

Removed unused reinit function

refs: https://github.com/TryGhost/Ghost/pull/11987
refs: 7e28802b1c
refs: 0b79abf5b2
refs: https://github.com/TryGhost/Ghost/issues/12003

- renit was added in https://github.com/TryGhost/Ghost/pull/11987
- it was then refactored out in 7e28802b1c (I think inadvertently)
- but we no longer call settings.init() before the DB is ready with the new boot proces 0b79abf5b2s
- original bugs, such as https://github.com/TryGhost/Ghost/issues/12003 could have regressed as a result of this being removed, but it is hard to reproduce
- by not initising settings before migrations, we reduce the complexity of needing to reinit them
- this commit actually just removes dead code, but I've left all the context I've found today here in this message so that it can be easily reconstructed if needed
This commit is contained in:
Hannah Wolfe 2021-06-30 12:44:32 +01:00
parent e410e16a5b
commit b33b837c39
No known key found for this signature in database
GPG key ID: 9F8C7532D0A6BA55
2 changed files with 0 additions and 123 deletions

View file

@ -27,23 +27,6 @@ module.exports = {
SettingsCache.init(settingsCollection);
},
async reinit() {
const oldSettings = SettingsCache.getAll();
SettingsCache.shutdown();
const settingsCollection = await models.Settings.populateDefaults();
const newSettings = SettingsCache.init(settingsCollection);
for (const model of settingsCollection.models) {
const key = model.attributes.key;
// The type of setting is object. That's why we need to compare the value of the `value` property.
if (newSettings[key].value !== oldSettings[key].value) {
model.emitChange(key + '.' + 'edited', {});
}
}
},
/**
* Handles syncronization of routes.yaml hash loaded in the frontend with
* the value stored in the settings table.

View file

@ -1,106 +0,0 @@
const sinon = require('sinon');
const should = require('should');
const rewire = require('rewire');
const settings = rewire('../../../core/server/services/settings');
describe('UNIT: server settings', function () {
afterEach(function () {
sinon.restore();
});
describe('reinit', function () {
function setupSettings(oldSettings, newSettings) {
const spy = sinon.spy();
const models = {
Settings: {
populateDefaults: sinon.stub()
}
};
models.Settings.populateDefaults.resolves({
models: [{
attributes: {
key: 'db_hash'
},
emitChange: spy
}]
});
const cache = {
getAll: sinon.stub(),
init: sinon.stub(),
shutdown: sinon.stub()
};
cache.getAll.returns(oldSettings);
cache.init.returns(newSettings);
settings.__set__({
models,
SettingsCache: cache
});
return spy;
}
it('emit is not fired when the settings value is same', async function () {
const oldSettings = {
db_hash: {
id: '5f4e32961c5a161b10dbff99',
group: 'core',
key: 'db_hash',
value: '342c470a-d4e2-4aa1-9dd3-fb5f11d82db6',
type: 'string',
flags: null,
created_at: '2020-09-01T11:37:58.000Z',
created_by: '1',
updated_at: '2020-09-01T11:37:58.000Z',
updated_by: '1'
}
};
const newSettings = oldSettings;
const spy = setupSettings(oldSettings, newSettings);
await settings.reinit();
spy.calledWith('db_hash.edited', {}).should.not.be.true();
});
it('emit is fired when the settings value is changed', async function () {
const oldSettings = {
db_hash: {
id: '5f4e32961c5a161b10dbff99',
group: 'core',
key: 'db_hash',
value: '342c470a-d4e2-4aa1-9dd3-fb5f11d82db6',
type: 'string',
flags: null,
created_at: '2020-09-01T11:37:58.000Z',
created_by: '1',
updated_at: '2020-09-01T11:37:58.000Z',
updated_by: '1'
}
};
const newSettings = {
db_hash: {
id: '5f4e32961c5a161b10dbff99',
group: 'core',
key: 'db_hash',
value: '12345', // changed
type: 'string',
flags: null,
created_at: '2020-09-01T11:37:58.000Z',
created_by: '1',
updated_at: '2020-09-01T11:37:58.000Z',
updated_by: '1'
}
};
const spy = setupSettings(oldSettings, newSettings);
await settings.reinit();
spy.calledWith('db_hash.edited', {}).should.be.true();
});
});
});