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?"`
This commit is contained in:
parent
6480cfb161
commit
562e8af26a
@ -108,7 +108,7 @@ type QueryOptions = {
|
||||
|
||||
interface PostsRepository {
|
||||
getAll(options: QueryOptions): Promise<CollectionPost[]>;
|
||||
getAllIds(): Promise<string[]>;
|
||||
getAllIds(options?: {transaction: Knex.Transaction}): Promise<string[]>;
|
||||
}
|
||||
|
||||
export class CollectionsService {
|
||||
@ -129,7 +129,7 @@ export class CollectionsService {
|
||||
this.slugService = deps.slugService;
|
||||
}
|
||||
|
||||
private async toDTO(collection: Collection): Promise<CollectionDTO> {
|
||||
private async toDTO(collection: Collection, options?: {transaction: Knex.Transaction}): Promise<CollectionDTO> {
|
||||
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<CollectionDTO | null> {
|
||||
@ -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
|
||||
|
@ -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<string[]>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user