mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Moved collections initialisation behind labs flag (#17057)
We ran into an issue where the large `published:true` query was affecting the boot time of large sites which had knock-on effects with availability.
This commit is contained in:
parent
2e3d2e1121
commit
41cbc40353
3 changed files with 33 additions and 31 deletions
|
@ -1,15 +0,0 @@
|
|||
module.exports = [{
|
||||
title: 'Index',
|
||||
slug: 'index',
|
||||
description: 'Collection with all posts',
|
||||
type: 'automatic',
|
||||
deletable: false,
|
||||
filter: 'status:published'
|
||||
}, {
|
||||
title: 'Featured Posts',
|
||||
slug: 'featured',
|
||||
description: 'Collection of featured posts',
|
||||
type: 'automatic',
|
||||
deletable: false,
|
||||
filter: 'featured:true'
|
||||
}];
|
|
@ -2,6 +2,7 @@ const {
|
|||
CollectionsService,
|
||||
CollectionsRepositoryInMemory
|
||||
} = require('@tryghost/collections');
|
||||
const labs = require('../../../shared/labs');
|
||||
|
||||
class CollectionsServiceWrapper {
|
||||
/** @type {CollectionsService} */
|
||||
|
@ -9,7 +10,6 @@ class CollectionsServiceWrapper {
|
|||
|
||||
constructor() {
|
||||
const postsRepository = require('./PostsRepository').getInstance();
|
||||
const events = require('../../lib/common/events');
|
||||
const collectionsRepositoryInMemory = new CollectionsRepositoryInMemory();
|
||||
|
||||
const collectionsService = new CollectionsService({
|
||||
|
@ -17,6 +17,36 @@ class CollectionsServiceWrapper {
|
|||
postsRepository: postsRepository
|
||||
});
|
||||
|
||||
this.api = collectionsService;
|
||||
}
|
||||
|
||||
async init() {
|
||||
if (!labs.isSet('collections')) {
|
||||
return;
|
||||
}
|
||||
const existingBuiltins = await this.api.getAll({filter: 'slug:featured'});
|
||||
|
||||
if (!existingBuiltins.data.length) {
|
||||
await this.api.createCollection({
|
||||
title: 'Index',
|
||||
slug: 'index',
|
||||
description: 'Collection with all posts',
|
||||
type: 'automatic',
|
||||
deletable: false,
|
||||
filter: 'status:published'
|
||||
});
|
||||
|
||||
await this.api.createCollection({
|
||||
title: 'Featured Posts',
|
||||
slug: 'featured',
|
||||
description: 'Collection of featured posts',
|
||||
type: 'automatic',
|
||||
deletable: false,
|
||||
filter: 'featured:true'
|
||||
});
|
||||
}
|
||||
|
||||
const events = require('../../lib/common/events');
|
||||
// @NOTE: these should be reworked to use the "Event" classes
|
||||
// instead of Bookshelf model events
|
||||
const updateEvents = require('./update-events');
|
||||
|
@ -24,23 +54,9 @@ class CollectionsServiceWrapper {
|
|||
// @NOTE: naive update implementation to keep things simple for the first version
|
||||
for (const event of updateEvents) {
|
||||
events.on(event, () => {
|
||||
collectionsService.updateAutomaticCollections();
|
||||
this.api.updateAutomaticCollections();
|
||||
});
|
||||
}
|
||||
|
||||
this.api = collectionsService;
|
||||
}
|
||||
|
||||
async init() {
|
||||
const existingBuiltins = await this.api.getAll({filter: 'slug:featured'});
|
||||
|
||||
if (!existingBuiltins.data.length) {
|
||||
const builtInCollections = require('./built-in-collections');
|
||||
|
||||
for (const collection of builtInCollections) {
|
||||
await this.api.createCollection(collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ describe('Collections API', function () {
|
|||
let agent;
|
||||
|
||||
before(async function () {
|
||||
mockManager.mockLabsEnabled('collections');
|
||||
agent = await agentProvider.getAdminAPIAgent();
|
||||
await fixtureManager.init('users', 'posts');
|
||||
await agent.loginAsOwner();
|
||||
|
|
Loading…
Add table
Reference in a new issue