Skip to content

Commit

Permalink
Merge pull request #6826 from steedos/Task]-优化find性能;清理beforeAggregat…
Browse files Browse the repository at this point in the history
…e、afterAggregate触发器-#6823

[Task]: 优化find性能;清理beforeAggregate、afterAggregate触发器 #6823
  • Loading branch information
sunhaolin authored May 11, 2024
2 parents 956c2e8 + 375b5ef commit 63b5ff5
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 344 deletions.
3 changes: 2 additions & 1 deletion packages/standard-objects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@steedos/filters": "2.7.1-beta.8",
"@steedos/i18n": "2.7.1-beta.8",
"@steedos/metadata-core": "2.7.1-beta.8",
"@steedos/metadata-registrar": "2.7.1-beta.8"
"@steedos/metadata-registrar": "2.7.1-beta.8",
"clone": "^2.1.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: [email protected]
* @Date: 2021-11-03 15:15:45
* @LastEditors: 孙浩林 [email protected]
* @LastEditTime: 2023-07-11 11:57:15
* @LastEditTime: 2024-05-11 13:45:34
* @Description:
*/

Expand All @@ -11,6 +11,7 @@ const auth = require("@steedos/auth");
const { checkAPIName } = require('../../util')
const register = require('@steedos/metadata-registrar');
const _ = require('underscore');
const clone = require('clone');

async function getAll(){
const schema = objectql.getSteedosSchema();
Expand Down Expand Up @@ -82,14 +83,15 @@ module.exports = {
const { spaceId } = this;
let dataList = await getAll();
if (!_.isEmpty(dataList)) {
const cloneValues = clone(this.data.values, false);
dataList.forEach((doc) => {
if (!_.find(this.data.values, (value) => {
return value.name === doc.name
})) {
this.data.values.push(doc);
cloneValues.push(doc);
}
})
const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
const records = objectql.getSteedosSchema().metadataDriver.find(cloneValues, this.query, spaceId);
if (records.length > 0) {
this.data.values = records;
} else {
Expand All @@ -116,20 +118,6 @@ module.exports = {
let result = await objectql.getObject(this.object_name).find(this.query, await auth.getSessionByUserId(this.userId, this.spaceId))
this.data.values = result.length;
},
afterAggregate: async function () {
if (this.data.values) {
const userSession = await auth.getSessionByUserId(this.userId);
const locale = userSession && userSession.locale;
const download = TAPi18n.__('queue_import_download', {returnObjects: true}, locale);
for (const value of this.data.values) {
if (value) {
// value.template_url = `[${download}](${objectql.absoluteUrl(`/api/data/download/template/${value._id}`)})`
// value.template_url = `<a href="${objectql.absoluteUrl(`/api/data/download/template/${value._id}`)}" target="_self">${download}</a>`
value.template_url = objectql.absoluteUrl(`/api/data/download/template/${value._id}`)
}
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
/*
* @Author: 孙浩林 [email protected]
* @Date: 2023-07-12 16:46:33
* @LastEditors: 孙浩林 [email protected]
* @LastEditTime: 2024-05-11 13:47:01
* @FilePath: /steedos-platform-2.3/services/service-charts/main/default/triggers/charts_metadata.trigger.js
* @Description:
*/
const objectql = require('@steedos/objectql');
const auth = require('@steedos/auth');
const register = require('@steedos/metadata-registrar')
const _ = require('underscore');
const clone = require('clone');
async function getAll(){
const schema = objectql.getSteedosSchema();
const configs = await register.registerChart.getAll(schema.broker)
Expand All @@ -28,22 +37,19 @@ module.exports = {
delete this.query.fields;
},

beforeAggregate: async function () {
delete this.query.fields;
},

afterFind: async function(){
const { spaceId } = this;
let dataList = await getAll();
if (!_.isEmpty(dataList)) {
const cloneValues = clone(this.data.values, false);
dataList.forEach((doc) => {
if (!_.find(this.data.values, (value) => {
return value.name === doc.name
})) {
this.data.values.push(doc);
cloneValues.push(doc);
}
})
const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
const records = objectql.getSteedosSchema().metadataDriver.find(cloneValues, this.query, spaceId);
if (records.length > 0) {
this.data.values = records;
} else {
Expand All @@ -52,25 +58,6 @@ module.exports = {
}

},
afterAggregate: async function(){
const { spaceId } = this;
let dataList = await getAll();
if (!_.isEmpty(dataList)) {
dataList.forEach((doc) => {
if (!_.find(this.data.values, (value) => {
return value.name === doc.name
})) {
this.data.values.push(doc);
}
})
const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
if (records.length > 0) {
this.data.values = records;
} else {
this.data.values.length = 0;
}
}
},
afterCount: async function(){
delete this.query.fields;
let result = await objectql.getObject(this.object_name).find(this.query, await auth.getSessionByUserId(this.userId, this.spaceId))
Expand Down
1 change: 1 addition & 0 deletions services/service-charts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@steedos/service-metadata-server": "2.7.1-beta.8",
"@steedos/service-package-loader": "2.7.1-beta.8",
"@steedos/service-steedos-server": "2.7.1-beta.8",
"clone": "^2.1.2",
"cross-env": "^7.0.3",
"dotenv-flow": "^3.2.0",
"ioredis": "^4.22.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@ const packages = require('../manager/packages');
const objectql = require('@steedos/objectql');
const auth = require('@steedos/auth');
const _ = require('lodash');
const clone = require('clone');
module.exports = {
listenTo: 'steedos_packages',
beforeFind: async function () {
delete this.query.fields;
},

beforeAggregate: async function () {
delete this.query.fields;
},

afterFind: async function(){
const { spaceId } = this;
let dataList = await packages.getAllPackages();
if (!_.isEmpty(dataList)) {
const cloneValues = clone(this.data.values, false);
dataList.forEach((doc) => {
if (!_.find(this.data.values, (value) => {
return value.name === doc.name
})) {
this.data.values.push(doc);
cloneValues.push(doc);
}
})
const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
const records = objectql.getSteedosSchema().metadataDriver.find(cloneValues, this.query, spaceId);
if (records.length > 0) {
this.data.values = records;
} else {
Expand All @@ -37,25 +35,7 @@ module.exports = {
}

},
afterAggregate: async function(){
const { spaceId } = this;
let dataList = await packages.getAllPackages();
if (!_.isEmpty(dataList)) {
dataList.forEach((doc) => {
if (!_.find(this.data.values, (value) => {
return value.name === doc.name
})) {
this.data.values.push(doc);
}
})
const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
if (records.length > 0) {
this.data.values = records;
} else {
this.data.values.length = 0;
}
}
},

afterCount: async function(){
delete this.query.fields;
let result = await objectql.getObject(this.object_name).find(this.query, await auth.getSessionByUserId(this.userId, this.spaceId))
Expand Down
1 change: 1 addition & 0 deletions services/service-package-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@steedos/metadata-core": "2.7.1-beta.8",
"@steedos/objectql": "2.7.1-beta.8",
"@steedos/service-package-loader": "2.7.1-beta.8",
"clone": "^2.1.2",
"fs-extra": "8.1.0",
"i18next": "20.3.2",
"json-stringify-safe": "5.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/*
* @Author: [email protected]
* @Date: 2022-04-10 14:34:08
* @LastEditors: baozhoutao@steedos.com
* @LastEditTime: 2023-05-30 16:14:11
* @LastEditors: 孙浩林 sunhaolin@steedos.com
* @LastEditTime: 2024-05-11 13:52:15
* @Description:
*/
const objectql = require('@steedos/objectql');
const register = require('@steedos/metadata-registrar');
const auth = require('@steedos/auth');
const _ = require('underscore');
const clone = require('clone');
async function getAll() {
const schema = objectql.getSteedosSchema();
const configs = await register.registerPage.getAll(schema.broker)
Expand Down Expand Up @@ -44,22 +45,19 @@ module.exports = {
delete this.query.fields;
},

beforeAggregate: async function () {
delete this.query.fields;
},

afterFind: async function () {
const { spaceId } = this;
let dataList = await getAll();
if (dataList) {
const cloneValues = clone(this.data.values, false);
dataList.forEach((doc) => {
if (!_.find(this.data.values, (value) => {
return value._id === doc._id
})) {
this.data.values.push(doc);
cloneValues.push(doc);
}
})
const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
const records = objectql.getSteedosSchema().metadataDriver.find(cloneValues, this.query, spaceId);
if (records.length > 0) {
this.data.values = records;
} else {
Expand All @@ -68,25 +66,7 @@ module.exports = {
}

},
afterAggregate: async function () {
const { spaceId } = this;
let dataList = await getAll();
if (dataList) {
dataList.forEach((doc) => {
if (!_.find(this.data.values, (value) => {
return value._id === doc._id
})) {
this.data.values.push(doc);
}
})
const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
if (records.length > 0) {
this.data.values = records;
} else {
this.data.values.length = 0;
}
}
},

afterCount: async function () {
delete this.query.fields;
let result = await objectql.getObject(this.object_name).find(this.query, await auth.getSessionByUserId(this.userId, this.spaceId))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/*
* @Author: [email protected]
* @Date: 2022-04-10 14:27:24
* @LastEditors: baozhoutao@steedos.com
* @LastEditTime: 2023-05-30 16:20:54
* @LastEditors: 孙浩林 sunhaolin@steedos.com
* @LastEditTime: 2024-05-11 13:53:30
* @Description:
*/
const objectql = require('@steedos/objectql');
const auth = require('@steedos/auth');
const _ = require('underscore');
const register = require('@steedos/metadata-registrar');
const clone = require('clone');
async function getAll(){
const schema = objectql.getSteedosSchema();
const configs = await register.registerPage.getAll(schema.broker)
Expand Down Expand Up @@ -39,22 +40,19 @@ module.exports = {
delete this.query.fields;
},

beforeAggregate: async function () {
delete this.query.fields;
},

afterFind: async function(){
const { spaceId } = this;
let dataList = await getAll();
if (dataList) {
const cloneValues = clone(this.data.values, false);
dataList.forEach((doc) => {
if (!_.find(this.data.values, (value) => {
return value._id === doc._id
})) {
this.data.values.push(doc);
cloneValues.push(doc);
}
})
const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
const records = objectql.getSteedosSchema().metadataDriver.find(cloneValues, this.query, spaceId);
if (records.length > 0) {
this.data.values = records;
} else {
Expand All @@ -63,25 +61,7 @@ module.exports = {
}

},
afterAggregate: async function(){
const { spaceId } = this;
let dataList = await getAll();
if (dataList) {
dataList.forEach((doc) => {
if (!_.find(this.data.values, (value) => {
return value._id === doc._id
})) {
this.data.values.push(doc);
}
})
const records = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
if (records.length > 0) {
this.data.values = records;
} else {
this.data.values.length = 0;
}
}
},

afterCount: async function(){
delete this.query.fields;
let result = await objectql.getObject(this.object_name).find(this.query, await auth.getSessionByUserId(this.userId, this.spaceId))
Expand Down
Loading

0 comments on commit 63b5ff5

Please sign in to comment.