api: use current connection on collection service (#5369)

Allow to retrieve collections in the middle of a transaction
This commit is contained in:
José Varela
2021-04-29 15:32:16 +01:00
committed by GitHub
parent 167b41bf7a
commit 72b516a678

View File

@@ -14,17 +14,20 @@ import { FieldsService } from '../services/fields';
import { ItemsService, MutationOptions } from '../services/items';
import cache from '../cache';
import { systemCollectionRows } from '../database/system-data/collections';
import SchemaInspector from '@directus/schema';
import env from '../env';
import logger from '../logger';
export class CollectionsService {
knex: Knex;
accountability: Accountability | null;
schemaInspector: typeof schemaInspector;
schema: SchemaOverview;
constructor(options: AbstractServiceOptions) {
this.knex = options.knex || database;
this.accountability = options.accountability || null;
this.schemaInspector = options.knex ? SchemaInspector(options.knex) : schemaInspector;
this.schema = options.schema;
}
@@ -146,7 +149,7 @@ export class CollectionsService {
accountability: this.accountability,
});
let tablesInDatabase = await schemaInspector.tableInfo();
let tablesInDatabase = await this.schemaInspector.tableInfo();
if (this.accountability && this.accountability.admin !== true) {
const collectionsYouHavePermissionToRead: string[] = this.schema.permissions
@@ -218,7 +221,7 @@ export class CollectionsService {
}
}
const tablesInDatabase = await schemaInspector.tableInfo();
const tablesInDatabase = await this.schemaInspector.tableInfo();
const tables = tablesInDatabase.filter((table) => collectionKeys.includes(table.name));
const meta = (await collectionItemsService.readByQuery({