diff --git a/ghost/collections/src/CollectionsService.ts b/ghost/collections/src/CollectionsService.ts index 9f7e8b9928..2db7334a4c 100644 --- a/ghost/collections/src/CollectionsService.ts +++ b/ghost/collections/src/CollectionsService.ts @@ -108,7 +108,7 @@ type QueryOptions = { interface PostsRepository { getAll(options: QueryOptions): Promise; - getAllIds(): Promise; + getAllIds(options?: {transaction: Knex.Transaction}): Promise; } export class CollectionsService { @@ -129,7 +129,7 @@ export class CollectionsService { this.slugService = deps.slugService; } - private async toDTO(collection: Collection): Promise { + private async toDTO(collection: Collection, options?: {transaction: Knex.Transaction}): Promise { const dto = { id: collection.id, title: collection.title, @@ -146,7 +146,7 @@ export class CollectionsService { })) }; if (collection.slug === 'latest') { - const allPostIds = await this.postsRepository.getAllIds(); + const allPostIds = await this.postsRepository.getAllIds(options); dto.posts = allPostIds.map((id, index) => ({ id, sort_order: index @@ -574,7 +574,7 @@ export class CollectionsService { if (!collection) { return null; } - return this.toDTO(collection); + return this.toDTO(collection, options); } async getBySlug(slug: string, options?: {transaction: Knex.Transaction}): Promise { @@ -582,7 +582,7 @@ export class CollectionsService { if (!collection) { return null; } - return this.toDTO(collection); + return this.toDTO(collection, options); } // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/ghost/core/core/server/services/collections/PostsRepository.js b/ghost/core/core/server/services/collections/PostsRepository.js index 84460b49dd..6f7e938271 100644 --- a/ghost/core/core/server/services/collections/PostsRepository.js +++ b/ghost/core/core/server/services/collections/PostsRepository.js @@ -4,8 +4,13 @@ class PostsRepository { this.moment = moment; } - async getAllIds() { - const rows = await this.models.Post.query().select('id').where('type', 'post'); + /** + * @param {Object} options + * @returns Promise + */ + async getAllIds({transaction} = {}) { + const query = this.models.Post.query().select('id').where('type', 'post'); + const rows = transaction ? await query.transacting(transaction) : await query; return rows.map(row => row.id); }