瀏覽代碼

数据查询优化

MaiXinRong 3 年之前
父節點
當前提交
9884f0712e
共有 2 個文件被更改,包括 45 次插入2 次删除
  1. 2 2
      app/service/stage_bills.js
  2. 43 0
      test/app/temp_test.test.js

+ 2 - 2
app/service/stage_bills.js

@@ -110,7 +110,7 @@ module.exports = app => {
                 '  Where tid = ? and sid = ? ' + filterSql;
 
             const result = await this.db.query(sql, [tid, sid]);
-            const stageBills = this.ctx.helper.filterLastestData(result, 'lid');
+            const stageBills = this.ctx.helper.filterLastestData(result, ['lid']);
             if (!lid || lid instanceof Array) return stageBills;
             return stageBills[0];
         }
@@ -121,7 +121,7 @@ module.exports = app => {
                         '  Where tid = ? and sid = ? And (`times` < ? OR (`times` = ? AND `order` <= ?)) ' + filterSql;
 
             const result = await this.db.query(sql, [tid, sid, times, times, order]);
-            const stageBills = this.ctx.helper.filterLastestData(result, 'lid');
+            const stageBills = this.ctx.helper.filterLastestData(result, ['lid']);
             if (!lid || lid instanceof Array) return stageBills;
             return stageBills[0];
         }

+ 43 - 0
test/app/temp_test.test.js

@@ -0,0 +1,43 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const { app, assert } = require('egg-mock/bootstrap');
+const mockData = {};
+const tenderId = 3992;
+const stageOrder = 1;
+const postData = {
+    account: 'fuqingqing',
+    project: 'P0505',
+    project_password: '123456',
+};
+
+describe('temp_test.js', () => {
+    // 准备测试数据
+    before(function* () {
+        const ctx = app.mockContext();
+        // 模拟登录session
+        ctx.session = {};
+        const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2);
+        assert(loginResult);
+        mockData.session = ctx.session;
+    });
+    it('test temp', function* () {
+        const ctx = app.mockContext(mockData);
+        //  大数据材差 第一期
+        const stage = yield ctx.service.stage.getDataByCondition({ tid: tenderId, order: stageOrder });
+        console.time('oldQuery');
+        const oldResult = yield ctx.service.stageBills.getLastestStageData(tenderId, stage.id);
+        console.timeEnd('oldQuery');
+        console.time('newQuery');
+        const newResult = yield ctx.service.stageBills.getLastestStageData2(tenderId, stage.id);
+        console.timeEnd('newQuery');
+        assert(oldResult.length === newResult.length);
+    });
+});