Skip to content

Commit

Permalink
fix: use db distinct to refact tags retreiving
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Sep 29, 2021
1 parent 0cd63b8 commit abf40ce
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions packages/system-server/src/router/function/get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author: Maslow<wangfugen@126.com>
* @Date: 2021-08-30 16:51:19
* @LastEditTime: 2021-09-28 17:21:46
* @LastEditTime: 2021-09-29 12:12:36
* @Description:
*/

Expand Down Expand Up @@ -119,21 +119,12 @@ export async function handleGetAllFunctionTags(req: Request, res: Response) {
const db = DatabaseAgent.sys_accessor.db

const docs = await db.collection<FunctionStruct>(Constants.cn.functions)
.find({
tags: { $exists: true, $ne: [] },
.distinct('tags', {
appid: app.appid
}, {
projection: { tags: 1 }

})
.toArray()

const all_tags = []
for (const doc of docs) {
const tags = doc.tags
all_tags.push(...tags)
}
const rets = Array.from(new Set(all_tags))
return res.send({
data: rets
data: docs
})
}

0 comments on commit abf40ce

Please sign in to comment.