Skip to content

Commit aaa1cb7

Browse files
authored
perf: plugin name (#275)
* Install packages * fix: tag union field * perf: plugin name
1 parent f4dd60b commit aaa1cb7

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

lib/mongo/models/plugins.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ export const PluginZodSchema = z.object({
1212
export type MongoPluginSchemaType = z.infer<typeof PluginZodSchema>;
1313

1414
const pluginMongooseSchema = new Schema({
15-
toolId: { type: String },
16-
type: { type: String, required: true, enum: Object.values(pluginTypeEnum.enum) }
15+
toolId: { type: String, required: true },
16+
type: { type: String, required: true, enum: Object.values(pluginTypeEnum.enum) },
17+
18+
// @deprecated
19+
objectName: { type: String }
1720
});
1821

19-
pluginMongooseSchema.index({ toolId: 1 }, { unique: true, sparse: true });
20-
pluginMongooseSchema.index({ type: 1 });
22+
pluginMongooseSchema.index({ type: 1, toolId: 1 }, { unique: true });
2123

22-
export const MongoPlugin = getMongoModel('system_plugins', pluginMongooseSchema);
24+
export const MongoSystemPlugin = getMongoModel('system_plugins', pluginMongooseSchema);

modules/tool/api/upload/confirmUpload.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { s } from '@/router/init';
22
import { contract } from '@/contract';
33
import { UploadToolsS3Path } from '@tool/constants';
4-
import { MongoPlugin, pluginTypeEnum } from '@/mongo/models/plugins';
4+
import { MongoSystemPlugin, pluginTypeEnum } from '@/mongo/models/plugins';
55
import { refreshVersionKey } from '@/cache';
66
import { SystemCacheKeyEnum } from '@/cache/type';
77
import { mongoSessionRun } from '@/mongo/utils';
@@ -28,10 +28,10 @@ export default s.route(contract.tool.upload.confirmUpload, async ({ body }) => {
2828

2929
await mongoSessionRun(async (session) => {
3030
const allToolsInstalled = (
31-
await MongoPlugin.find({ type: pluginTypeEnum.enum.tool }).lean()
31+
await MongoSystemPlugin.find({ type: pluginTypeEnum.enum.tool }).lean()
3232
).map((tool) => tool.toolId);
3333
// create all that not exists
34-
await MongoPlugin.create(
34+
await MongoSystemPlugin.create(
3535
toolIds
3636
.filter((toolId) => !allToolsInstalled.includes(toolId))
3737
.map((toolId) => ({

modules/tool/api/upload/delete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { contract } from '@/contract';
2-
import { MongoPlugin } from '@/mongo/models/plugins';
2+
import { MongoSystemPlugin } from '@/mongo/models/plugins';
33
import { mongoSessionRun } from '@/mongo/utils';
44
import { s } from '@/router/init';
55
import { privateS3Server, publicS3Server } from '@/s3';
@@ -11,7 +11,7 @@ import { addLog } from '@/utils/log';
1111
export default s.route(contract.tool.upload.delete, async ({ query: { toolId } }) => {
1212
addLog.debug(`Deleting tool: ${toolId}`);
1313
const res = await mongoSessionRun(async (session) => {
14-
const result = await MongoPlugin.findOneAndDelete({ toolId }).session(session);
14+
const result = await MongoSystemPlugin.findOneAndDelete({ toolId }).session(session);
1515
if (!result || !result.toolId) {
1616
return {
1717
status: 404,

modules/tool/api/upload/install.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { join } from 'path';
55
import { batch } from '@/utils/parallel';
66
import { parsePkg } from '@tool/utils';
77
import { writeFile } from 'fs/promises';
8-
import { MongoPlugin, pluginTypeEnum } from '@/mongo/models/plugins';
8+
import { MongoSystemPlugin, pluginTypeEnum } from '@/mongo/models/plugins';
99
import { refreshVersionKey } from '@/cache';
1010
import { SystemCacheKeyEnum } from '@/cache/type';
1111
import { addLog } from '@/utils/log';
@@ -30,11 +30,11 @@ export default s.route(contract.tool.upload.install, async ({ body }) => {
3030
<T>(item: T): item is NonNullable<T> => !!item
3131
);
3232

33-
const allToolsInstalled = (await MongoPlugin.find({ type: pluginTypeEnum.enum.tool }).lean()).map(
34-
(tool) => tool.toolId
35-
);
33+
const allToolsInstalled = (
34+
await MongoSystemPlugin.find({ type: pluginTypeEnum.enum.tool }).lean()
35+
).map((tool) => tool.toolId);
3636
// create all that not exists
37-
await MongoPlugin.create(
37+
await MongoSystemPlugin.create(
3838
toolIds
3939
.filter((toolId) => !allToolsInstalled.includes(toolId))
4040
.map((toolId) => ({

modules/tool/init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { join } from 'path';
33
import { readdir } from 'fs/promises';
44
import type { ToolMapType } from './type';
55
import { isProd } from '@/constants';
6-
import { MongoPlugin } from '@/mongo/models/plugins';
6+
import { MongoSystemPlugin } from '@/mongo/models/plugins';
77
import { refreshDir } from '@/utils/fs';
88
import { addLog } from '@/utils/log';
99
import { basePath, toolsDir, UploadToolsS3Path } from './constants';
@@ -33,7 +33,7 @@ export async function initTools() {
3333
await refreshDir(toolsDir);
3434
// 1. download pkgs into pkg dir
3535
// 1.1 get tools from mongo
36-
const toolsInMongo = await MongoPlugin.find({
36+
const toolsInMongo = await MongoSystemPlugin.find({
3737
type: 'tool'
3838
}).lean();
3939

0 commit comments

Comments
 (0)