mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
Forced "latest" Collection Entity to have no posts
refs https://github.com/TryGhost/Arch/issues/95 We're going to be treating the "latest" Collection as a "virtual" Collection where we will hydrate the posts from the posts repository. This will allow for more performant queries, and less work to keep the "latest" Collection in sync
This commit is contained in:
parent
3a624ec3a1
commit
45c1a82909
@ -136,6 +136,9 @@ export class Collection {
|
||||
* @param index {number} - The index to insert the post at, use negative numbers to count from the end.
|
||||
*/
|
||||
addPost(post: CollectionPost, index: number = -0) {
|
||||
if (this.slug === 'latest') {
|
||||
return false;
|
||||
}
|
||||
if (this.type === 'automatic') {
|
||||
const matchesFilter = this.postMatchesFilter(post);
|
||||
|
||||
@ -268,7 +271,7 @@ export class Collection {
|
||||
createdAt: Collection.validateDateField(data.created_at, 'created_at'),
|
||||
updatedAt: Collection.validateDateField(data.updated_at, 'updated_at'),
|
||||
deleted: data.deleted || false,
|
||||
posts: data.posts || []
|
||||
posts: data.slug !== 'latest' ? (data.posts || []) : []
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -339,6 +339,27 @@ describe('Collection', function () {
|
||||
assert(collection.posts[collection.posts.length - 2] === '3');
|
||||
});
|
||||
|
||||
it('Does not add a post to the latest collection', async function () {
|
||||
const collection = await Collection.create({
|
||||
title: 'Testing adding to latest',
|
||||
slug: 'latest',
|
||||
type: 'automatic',
|
||||
filter: ''
|
||||
});
|
||||
|
||||
assert.equal(collection.posts.length, 0, 'Collection should have no posts');
|
||||
|
||||
const added = await collection.addPost({
|
||||
id: '0',
|
||||
featured: false,
|
||||
published_at: new Date(),
|
||||
tags: []
|
||||
});
|
||||
|
||||
assert.equal(added, false);
|
||||
assert.equal(collection.posts.length, 0, 'The non-featured post should not have been added');
|
||||
});
|
||||
|
||||
it('Adds a post to an automatic collection when it matches the filter', async function () {
|
||||
const collection = await Collection.create({
|
||||
title: 'Testing adding posts',
|
||||
|
Loading…
Reference in New Issue
Block a user