-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6826 from steedos/Task]-优化find性能;清理beforeAggregat…
- Loading branch information
Showing
26 changed files
with
112 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
*/ | ||
|
||
|
@@ -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(); | ||
|
@@ -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 { | ||
|
@@ -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}`) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
@@ -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 { | ||
|
@@ -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)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
@@ -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 { | ||
|
@@ -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)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
@@ -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 { | ||
|
@@ -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)) | ||
|
Oops, something went wrong.