ionic4 - 第一次执行时的 SQLite 性能
问题描述
我正在使用带有离子的 SQLite
Ionic:
Ionic CLI : 6.6.0 (C:\Users\ADEEL\AppData\Roaming\npm\node_modules\@ionic\cli)
Ionic Framework : @ionic/angular 5.0.5
@angular-devkit/build-angular : 0.900.7
@angular-devkit/schematics : 9.0.7
@angular/cli : 9.0.7
@ionic/angular-toolkit : 2.2.0
Cordova:
Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.1.0, browser 6.0.0
Cordova Plugins : cordova-plugin-ionic-webview 4.1.3, (and 9 other plugins)
Utility:
cordova-res (update available: 0.13.0) : 0.6.0
native-run (update available: 1.0.0) : 0.2.8
System:
Android SDK Tools : 26.1.1 (C:\Users\ADEEL\AppData\Local\Android\Sdk)
NodeJS : v12.16.1 (C:\Program Files\nodejs\node.exe)
npm : 6.13.4
OS : Windows 10
我有一个表,在 log_book 表中有 16 条记录,在部门和位置各有 1 条记录。当我第一次运行查询时,它将花费将近 15 到 20 秒,但之后它会以毫秒为单位运行。调用函数如下
getLogBooks(): Promise<LogBook[]>{
return this.storage.executeSql(`SELECT l.id, l.log_book_id, IFNULL(l.machine_no, "") machine_no , d.department_name, loc.location_name, l.section, l.area
FROM log_book l
INNER JOIN departments d ON l.department_id = d.id
INNER JOIN locations loc ON l.location_id = loc.id
WHERE l.deleted_at IS NULL`, [])
.then(res => {
const items: LogBook[] = [];
console.log('Log BOOK', res.rows.length)
if (res.rows.length > 0) {
for (let i = 0; i < res.rows.length; i++) {
items.push({
id: res.rows.item(i).id,
LogBookID: res.rows.item(i).log_book_id,
MachineNo: res.rows.item(i).machine_no,
Department: res.rows.item(i).department_name,
Location: res.rows.item(i).location_name,
Section: res.rows.item(i).section,
Area: res.rows.item(i).area
});
}
}
return items;
});
}
表结构
CREATE TABLE IF NOT EXISTS `log_book` (
`id` integer primary key autoincrement,
`log_book_id` varchar(50) NOT NULL,
`machine_no` varchar(50) DEFAULT NULL,
`department_id` int(11) NOT NULL,
`location_id` int(11) NOT NULL,
`section` varchar(50) NOT NULL,
`area` varchar(50) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`created_by` int(11) DEFAULT NULL,
`updated_by` int(11) DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL
);
CREATE TABLE IF NOT EXISTS `departments` (
`id` integer primary key autoincrement,
`department_name` varchar(50) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`created_by` int(11) DEFAULT NULL,
`updated_by` int(11) DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL
);
CREATE TABLE IF NOT EXISTS `locations` (
`id` integer primary key autoincrement,
`location_name` varchar(50) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`created_by` int(11) DEFAULT NULL,
`updated_by` int(11) DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL
);
我做错了什么。
感谢你在期待
解决方案
推荐阅读
- python-3.x - 尝试将 tf-nightly-gpu 与 RTX 30 卡一起使用
- javascript - 如何正确映射一个数组,该数组来自我在 mapStateToProps 中定义的属性之一,以便在我的表单中选择下拉菜单?
- android - 通过 URL 获取 SSL 证书链的方法有哪些?
- outlook - 未收到包含自定义属性的日历事件的更改通知
- db2 - 无法更改表格列
- javascript - 将 curl 命令中的数组传递给 mongoDB
- python - 在 python 中的 PCA 重建中查找 rmse 的问题
- selenium - Selenium python:找到并单击
- from里面的文字
- from里面的文字
- xaml - MasterDetail页面调试错误:CS0263
- python - 如何根据 id 和“原始日期”范围填充熊猫数据框?