We use typeorm in our node.js application and it seems that loading the entities on startup is adding a significant amount of time. Or db schema is fairly small/simple however loading the application seems to take upwards of 2 minutes. If I pass an empty array (no entities) then the app loads significantly faster.
- How can I enable logging in typeorm for initialization?
- Is there a way to reduce loading times?
export const entities = [
Account,
Bundle,
Category,
Customer,
Device,
Event,
EventMember,
GoldrushMasterEvent,
Order,
Organization,
OrganizationGroup,
Province,
Role,
Ticket,
TicketPackage,
SalesReportView,
User,
SystemConfig,
TicketDetailsView,
EventMemberSalesView,
Invoice,
InvoiceItem,
InvoiceItemCode,
EventSalesView,
OrderDetailsView
];
export interface DatabaseConnectionOptions {
connectionName?: string;
username: string;
password: string;
host: string;
port: number;
database: string;
maxPoolSize: number;
}
/**
* Uses type orm to connect to the RDS instance
*
* @param options
*/
const connectDatabase = async (options: DatabaseConnectionOptions): Promise<void> => {
const dbConfig: ConnectionOptions = {
name: options.connectionName,
type: 'postgres',
schema: 'public',
entities: entities,
synchronize: false,
logging: process.env.DB_LOGGING === 'true',
logger: 'advanced-console',
username: options.username,
password: options.password,
host: options.host,
port: options.port,
database: options.database,
extra: {
max: options.maxPoolSize
},
// log anything that takes more than a second
maxQueryExecutionTime: 1000
};
await createConnection(dbConfig);
};