node.js - PostgreSQL 的 TypeORM 性能问题
问题描述
我对 TypeORM 和 PostgreSQL 有一个奇怪的问题。下面是nest.js 中代码的简单部分
@Get()
async getHello(): Promise<any> {
const keywords = 'wxample';
const now1: any = new Date();
await this.typeormConnection.query(`
select admins.first_name from sessions
JOIN admins ON sessions.admin_id = admins."id"
LEFT JOIN companies ON companies."id" = admins.company_id
WHERE admin_sessions.token = '${keywords}'
`);
const now2: any = new Date();
await this.pgConnection.query(`
select admins.first_name from sessions
JOIN admins ON sessions.admin_id = admins."id"
LEFT JOIN companies ON companies."id" = admins.company_id
WHERE admin_sessions.token = '${keywords}'
`);
console.log(`typeorm => ${now2 - now1}ms`);
console.log(`pg => ${(new Date() as any) - now2}ms`);
return 'ok';
}
如果我将它连接到 Azure PostgreSQL,平均结果时间将是:
typeorm => 1300ms
pg => 30ms
但如果我将此代码连接到 AWS,结果将是:
typeorm => 100ms
pg => 30ms
我想知道为什么 tge pure pg 模块在 Azure 上如此之快,但是 typeorm 需要时间,而 typeorm 在 AWS 中可以使用相同的数据库设置?
解决方案
推荐阅读
- python - 在列熊猫数据框中的 1 位数字前添加一个零
- python-3.x - 如何使用 python 在线程中启动 websocket 服务器?
- python-3.x - 如何使用python中的父类检查子类的类型?
- c++ - '[' token .. 和更多之前的预期主表达式
- r - 有没有办法在 R 中自动抓取(复制和粘贴)图像?
- xml - 公共变量值未重置
- javascript - Firebase 身份验证模拟器因 IDP 失败
- php - 如何从mysqli结果为php中的while循环中的数组赋值,以制作一个计数器来过滤另一个while循环?
- ios - 如果只使用 SKAdNetwork 而不是 IDFA for Admob,Apple 隐私问题
- ios - iOS testflight 上的 SDK 版本问题