From 562e8af26a87eeaae406d2a0916b7d77c81518f8 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Mon, 25 Sep 2023 11:49:10 +0100 Subject: [PATCH] Fixed saving collection card with `'latest'` collection on sqlite no issue - added passthrough of `transaction` property when fetching post IDs otherwise SQLite will error with ` "Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?"` --- ghost/collections/src/CollectionsService.ts | 10 +++++----- .../server/services/collections/PostsRepository.js | 9 +++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) 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); }