q-koa 13.2.6 → 13.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/app.js +31 -3
- package/core/config.js +1 -0
- package/core/file/plugins/model/service.js +21 -24
- package/core/file/plugins/system/controller.js +48 -0
- package/package.json +1 -1
package/core/app.js
CHANGED
|
@@ -90,7 +90,7 @@ class APP {
|
|
|
90
90
|
miLimit(config.rateLimit),
|
|
91
91
|
miStatic(config.static),
|
|
92
92
|
miAgent(),
|
|
93
|
-
miWebsocket(),
|
|
93
|
+
config.is_websocket ? miWebsocket() : null,
|
|
94
94
|
miCors(config.includes, config.ip),
|
|
95
95
|
// miRestc(config),
|
|
96
96
|
miBody(config.koaBody),
|
|
@@ -103,7 +103,7 @@ class APP {
|
|
|
103
103
|
miResponse(config.response),
|
|
104
104
|
// miToken(),
|
|
105
105
|
miErrors(),
|
|
106
|
-
]
|
|
106
|
+
].filter(Boolean)
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
async start() {
|
|
@@ -1226,6 +1226,34 @@ class APP {
|
|
|
1226
1226
|
}
|
|
1227
1227
|
if (['findOne', 'findAll', 'findAndCountAll'].includes(fn)) {
|
|
1228
1228
|
// 拆分
|
|
1229
|
+
if (
|
|
1230
|
+
fn === 'findOne' &&
|
|
1231
|
+
attributes &&
|
|
1232
|
+
attributes.length > 0 &&
|
|
1233
|
+
attributes.every(
|
|
1234
|
+
(attribute) =>
|
|
1235
|
+
Array.isArray(attribute) &&
|
|
1236
|
+
attribute.length === 2 &&
|
|
1237
|
+
attribute.some((o) => o.includes('SUM'))
|
|
1238
|
+
)
|
|
1239
|
+
) {
|
|
1240
|
+
const target = await app[appName].model[controller][fn]({
|
|
1241
|
+
attributes: attributes.map((attribute) => {
|
|
1242
|
+
if (Array.isArray(attribute)) {
|
|
1243
|
+
return attribute.map((att) => {
|
|
1244
|
+
if (att.startsWith('SUM')) {
|
|
1245
|
+
return Sequelize.literal(att)
|
|
1246
|
+
}
|
|
1247
|
+
return att
|
|
1248
|
+
})
|
|
1249
|
+
}
|
|
1250
|
+
return attribute
|
|
1251
|
+
}),
|
|
1252
|
+
where: _where,
|
|
1253
|
+
})
|
|
1254
|
+
|
|
1255
|
+
return ctx.SUCCESS(target)
|
|
1256
|
+
}
|
|
1229
1257
|
if (is_split) {
|
|
1230
1258
|
if (fn === 'findAndCountAll') {
|
|
1231
1259
|
const requiredInclude = myInclude
|
|
@@ -2188,7 +2216,7 @@ APP.getConfig = (app) => ({
|
|
|
2188
2216
|
} else {
|
|
2189
2217
|
app.cache.set(target, null)
|
|
2190
2218
|
|
|
2191
|
-
if (app.appConfig.appName) {
|
|
2219
|
+
if (app.appConfig.appName && app.appConfig.productionHost) {
|
|
2192
2220
|
const ipHost = (
|
|
2193
2221
|
Array.isArray(app.appConfig.productionHost)
|
|
2194
2222
|
? app.appConfig.productionHost
|
package/core/config.js
CHANGED
|
@@ -60,25 +60,25 @@ exports.loadModel = async ({ app, appName }) => {
|
|
|
60
60
|
// const id = ori_target ? ori_target.id : null
|
|
61
61
|
const id = i + 1
|
|
62
62
|
|
|
63
|
-
let countNumber = 0
|
|
64
|
-
if (!['setting', 'auth'].includes(config.belongs)) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
63
|
+
// let countNumber = 0
|
|
64
|
+
// if (!['setting', 'auth'].includes(config.belongs)) {
|
|
65
|
+
// if (currentDisabledFindAllList.length === 0 && app.model[result[i]]) {
|
|
66
|
+
// countNumber = await app.model[result[i]].count()
|
|
67
|
+
// }
|
|
68
|
+
// if (countNumber >= 500) {
|
|
69
|
+
// disabledFindAllList = [...disabledFindAllList, result[i]]
|
|
70
|
+
// const tableIndexList = await app.service.system.getTableIndex({
|
|
71
|
+
// app,
|
|
72
|
+
// model: result[i],
|
|
73
|
+
// })
|
|
74
|
+
// if (countNumber >= 100000) {
|
|
75
|
+
// console.warn('数据量大,请注意', result[i], countNumber)
|
|
76
|
+
// }
|
|
77
|
+
// if (tableIndexList.length <= 1) {
|
|
78
|
+
// console.warn(`${result[i]} count ${countNumber}没有索引`)
|
|
79
|
+
// }
|
|
80
|
+
// }
|
|
81
|
+
// }
|
|
82
82
|
|
|
83
83
|
const obj = {
|
|
84
84
|
id,
|
|
@@ -114,7 +114,7 @@ exports.loadModel = async ({ app, appName }) => {
|
|
|
114
114
|
list: attributes.map((attr, index) => {
|
|
115
115
|
const name = attr.match(/exports.(.*)=/)[1].trim()
|
|
116
116
|
let defaultValue = ''
|
|
117
|
-
if (model[name] && model[name]
|
|
117
|
+
if (model[name] && 'defaultValue' in model[name]) {
|
|
118
118
|
if (
|
|
119
119
|
typeof model[name].defaultValue === 'boolean' &&
|
|
120
120
|
model[name].defaultValue === true
|
|
@@ -165,10 +165,7 @@ exports.loadModel = async ({ app, appName }) => {
|
|
|
165
165
|
) {
|
|
166
166
|
defaultValue = 'null'
|
|
167
167
|
}
|
|
168
|
-
} else if (
|
|
169
|
-
model[name] &&
|
|
170
|
-
!model[name].hasOwnProperty('defaultValue')
|
|
171
|
-
) {
|
|
168
|
+
} else if (model[name] && !('defaultValue' in model[name])) {
|
|
172
169
|
defaultValue = "''"
|
|
173
170
|
}
|
|
174
171
|
|
|
@@ -883,3 +883,51 @@ exports.dropIndex = async (ctx) => {
|
|
|
883
883
|
|
|
884
884
|
ctx.SUCCESS(result)
|
|
885
885
|
}
|
|
886
|
+
|
|
887
|
+
exports.checkFrag = async (ctx) => {
|
|
888
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
889
|
+
const { model } = ctx.request.body
|
|
890
|
+
if (!model) return ctx.ERROR(`model?`)
|
|
891
|
+
|
|
892
|
+
const query = `SELECT table_name, ROUND((data_free / data_length) * 100, 2) AS fragmentation_percentage
|
|
893
|
+
FROM information_schema.TABLES
|
|
894
|
+
WHERE table_schema = '${app.sequelize.config.database}' AND table_name = '${model}';`
|
|
895
|
+
|
|
896
|
+
const result = await app.sequelize.query(query)
|
|
897
|
+
|
|
898
|
+
if (result && result[0]) {
|
|
899
|
+
return ctx.SUCCESS(result[0][0])
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
return ctx.SUCCESS({})
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
exports.reset = async (ctx) => {
|
|
906
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
907
|
+
const { model } = ctx.request.body
|
|
908
|
+
|
|
909
|
+
const count = await app.model[model].count()
|
|
910
|
+
if (count > 10000) {
|
|
911
|
+
return ctx.ERROR(`数据量太大,无法重置`)
|
|
912
|
+
}
|
|
913
|
+
const result = await app.model[model].findAll({
|
|
914
|
+
attributes: {
|
|
915
|
+
exclude: ['id'],
|
|
916
|
+
},
|
|
917
|
+
})
|
|
918
|
+
|
|
919
|
+
await app.model[model].sync({
|
|
920
|
+
force: true,
|
|
921
|
+
})
|
|
922
|
+
|
|
923
|
+
await app.model[model].bulkCreate(
|
|
924
|
+
result.map((item, index) => {
|
|
925
|
+
return {
|
|
926
|
+
...item.toJSON(),
|
|
927
|
+
id: index + 1,
|
|
928
|
+
}
|
|
929
|
+
})
|
|
930
|
+
)
|
|
931
|
+
|
|
932
|
+
ctx.SUCCESS(result.length)
|
|
933
|
+
}
|