q-koa 9.0.6 → 9.3.0

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 CHANGED
@@ -926,6 +926,24 @@ class APP {
926
926
  }
927
927
  }
928
928
 
929
+ if (fn === 'findAll') {
930
+ const disabledFindAllList = _.get(
931
+ app[appName],
932
+ 'appConfig.disabledFindAllList',
933
+ []
934
+ )
935
+ if (
936
+ disabledFindAllList.includes(controller) &&
937
+ !(
938
+ limit >= 0 ||
939
+ limit !== undefined ||
940
+ (where && !_.isEmpty(where))
941
+ )
942
+ ) {
943
+ throw new Error(`请使用条件`)
944
+ }
945
+ }
946
+
929
947
  let myInclude
930
948
  if (include) {
931
949
  if (relate) {
package/core/config.js CHANGED
@@ -131,6 +131,7 @@ module.exports = {
131
131
  excludes: ['admin'],
132
132
  },
133
133
  cacheModel: [],
134
+ disabledFindAllList: [],
134
135
  defaultRouter: (router) => (app) => {
135
136
  if (app.controller.cache) {
136
137
  router.get('/cache/get', app.controller.cache.get)
@@ -17,6 +17,7 @@ exports.loadModel = async ({ app, appName }) => {
17
17
  )
18
18
 
19
19
  const dataList = []
20
+ let disabledFindAllList = []
20
21
  const result = data.filter(
21
22
  (item) => !['model', 'model_attributes'].includes(item)
22
23
  )
@@ -60,6 +61,17 @@ exports.loadModel = async ({ app, appName }) => {
60
61
  // const ori_target = modelList.find((m) => m.model === result[i])
61
62
  // const id = ori_target ? ori_target.id : null
62
63
  const id = i + 1
64
+
65
+ let countNumber = 0
66
+ if (!['setting', 'auth'].includes(config.belongs)) {
67
+ if (app.model[result[i]]) {
68
+ countNumber = await app.model[result[i]].count()
69
+ }
70
+ if (countNumber >= 500) {
71
+ disabledFindAllList = [...disabledFindAllList, result[i]]
72
+ }
73
+ }
74
+
63
75
  const obj = {
64
76
  id,
65
77
  model: result[i],
@@ -211,6 +223,8 @@ exports.loadModel = async ({ app, appName }) => {
211
223
 
212
224
  await Promise.all([promise1, promise2])
213
225
  console.log('lodaModel success!')
226
+ console.warn(`disabledFindAllList: ${JSON.stringify(disabledFindAllList)}`)
227
+
214
228
  if (app.service.routes && app.model.routes) {
215
229
  await app.service.routes.initRouter({ app })
216
230
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "9.0.6",
3
+ "version": "9.3.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {