Fixed transaction errors using PostsService inside of Post model's onSaving hook (#18148)

no issue

`PostsService` and `CollectionsService` were missing some passthroughs and had differing naming for a transaction instance on the `options` object which meant SQLite would hang if the Lexical renderer called out to `PostsService.browsePosts`

- added passthrough of `transacting` to the Lexical renderer ready for implementation of the collection-fetching function
- added rename of `options.transacting` to `options.transaction` and passthrough from `PostsService` to `CollectionsService` (passthrough from collections repository to bookshelf and required `transaction->transacting` was already in place)
This commit is contained in:
Kevin Ansfield 2023-09-14 18:22:10 +01:00 committed by GitHub
parent bcb543d039
commit 1c68bd6779
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 7 deletions

View File

@ -559,12 +559,12 @@ export class CollectionsService {
});
}
async getById(id: string): Promise<Collection | null> {
return await this.collectionsRepository.getById(id);
async getById(id: string, options?: {transaction: Knex.Transaction}): Promise<Collection | null> {
return await this.collectionsRepository.getById(id, options);
}
async getBySlug(slug: string): Promise<Collection | null> {
return await this.collectionsRepository.getBySlug(slug);
async getBySlug(slug: string, options?: {transaction: Knex.Transaction}): Promise<Collection | null> {
return await this.collectionsRepository.getBySlug(slug, options);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any

View File

@ -700,7 +700,7 @@ Post = ghostBookshelf.Model.extend({
)
) {
try {
this.set('html', await lexicalLib.render(this.get('lexical')));
this.set('html', await lexicalLib.render(this.get('lexical'), {transacting: options.transacting}));
} catch (err) {
throw new errors.ValidationError({
message: tpl(messages.invalidLexicalStructure),

View File

@ -44,10 +44,10 @@ class PostsService {
async browsePosts(options) {
let posts;
if (options.collection) {
let collection = await this.collectionsService.getById(options.collection);
let collection = await this.collectionsService.getById(options.collection, {transaction: options.transacting});
if (!collection) {
collection = await this.collectionsService.getBySlug(options.collection);
collection = await this.collectionsService.getBySlug(options.collection, {transaction: options.transacting});
}
if (!collection) {