typeorm - typeorm 加载实体真的很慢
问题描述
我们在 node.js 应用程序中使用 typeorm,似乎在启动时加载实体会增加大量时间。或者 db 架构相当小/简单,但加载应用程序似乎需要 2 分钟以上。如果我传递一个空数组(没有实体),那么应用程序加载速度会显着加快。
- 如何启用登录 typeorm 以进行初始化?
- 有没有办法减少加载时间?
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);
};
解决方案
推荐阅读
- c# - 火力基地动态链接
- php - laravel 文件系统返回数据字符串而不是视频
- c - Char Driver Linux:file_operations读写的正确实现是什么?需要进行哪些偏移检查?
- python - 当利率和付款随时间变化时,如何使用 Pandas 计算投资的未来价值?
- javascript - 正则表达式逗号作为可选字符
- cassandra - Apache Cassandra 中临时数据的概念
- javascript - 根据另一个数组的顺序对数组进行排序 - 对输入
- c# - 如何制作编辑表格?
- c++ - 快速选择算法返回第 K 个最小元素。递归参数问题
- azure-data-factory - 如何在 Azure 数据工厂中参数化数据集定义文件名