q-koa 13.8.45 → 13.8.46
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.
|
@@ -543,22 +543,21 @@ exports.initDataWithCache = exports.initData = async (ctx) => {
|
|
|
543
543
|
const { app } = getAppByCtx(ctx)
|
|
544
544
|
const appConfig = getConfig(app)
|
|
545
545
|
|
|
546
|
-
const { is_cache } = await appConfig.getObject('base')
|
|
546
|
+
const { is_cache, version: cacheVersion } = await appConfig.getObject('base')
|
|
547
547
|
const { includes, excludes = [] } = ctx.request.body
|
|
548
548
|
if (!includes) {
|
|
549
549
|
return ctx.SUCCESS(null)
|
|
550
550
|
}
|
|
551
|
-
const cacheTarget = JSON.stringify(ctx.request.body)
|
|
551
|
+
const cacheTarget = is_cache ? JSON.stringify(ctx.request.body) : ''
|
|
552
552
|
|
|
553
|
-
let result = null
|
|
554
|
-
if (
|
|
555
|
-
result = cache.get(cacheTarget)
|
|
556
|
-
} else {
|
|
553
|
+
let result = is_cache ? cache.get(cacheTarget) : null
|
|
554
|
+
if (!result) {
|
|
557
555
|
result = await app.service.system.initData({
|
|
558
556
|
app,
|
|
559
557
|
includes,
|
|
560
558
|
excludes,
|
|
561
559
|
ctx,
|
|
560
|
+
cacheVersion,
|
|
562
561
|
})
|
|
563
562
|
if (is_cache && cacheTarget.includes('setting/findAll')) {
|
|
564
563
|
cache.set(cacheTarget, result)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const lodash = require('lodash')
|
|
2
|
-
const {
|
|
2
|
+
const { Sequelize } = require('q-koa')
|
|
3
3
|
const { formatLiteralObj, filterFunction } = require('../../utils')
|
|
4
4
|
const formatPostFunction = (str) => `eval(${str})`
|
|
5
5
|
const nodeVm = require('vm')
|
|
@@ -17,19 +17,17 @@ const getLiteral = (str) => {
|
|
|
17
17
|
}
|
|
18
18
|
return ''
|
|
19
19
|
}
|
|
20
|
-
exports.initData = async ({ includes, excludes, app, ctx }) => {
|
|
21
|
-
const appConfig = getConfig(app)
|
|
22
|
-
const { version: cacheVersion } = await appConfig.getObject('base')
|
|
23
|
-
|
|
20
|
+
exports.initData = async ({ includes, excludes, app, ctx, cacheVersion }) => {
|
|
24
21
|
const apiVersion = ctx.request.header.version
|
|
25
22
|
const config = ctx.request.header.config
|
|
26
23
|
|
|
27
24
|
if (!(excludes instanceof Array)) {
|
|
28
25
|
excludes = [excludes]
|
|
29
26
|
}
|
|
27
|
+
const excludeSet = new Set(excludes)
|
|
30
28
|
const result = await Promise.all(
|
|
31
29
|
Object.keys(includes)
|
|
32
|
-
.filter((item) =>
|
|
30
|
+
.filter((item) => excludeSet.has(item) || excludes.length === 0)
|
|
33
31
|
.map((item) => {
|
|
34
32
|
const route = includes[item]
|
|
35
33
|
if (lodash.isObject(route)) {
|
|
@@ -125,14 +123,17 @@ exports.initData = async ({ includes, excludes, app, ctx }) => {
|
|
|
125
123
|
Array.isArray(excludeInclude) &&
|
|
126
124
|
excludeInclude.length > 0
|
|
127
125
|
) {
|
|
126
|
+
const excludeNameSet = new Set(excludeInclude)
|
|
127
|
+
const excludeModelSet = new Set(
|
|
128
|
+
excludeInclude
|
|
129
|
+
.map((m) => app.model[m])
|
|
130
|
+
.filter((m) => m !== undefined)
|
|
131
|
+
)
|
|
128
132
|
myInclude = myInclude.filter((i) => {
|
|
129
|
-
if (
|
|
130
|
-
if (
|
|
133
|
+
if (excludeNameSet.has(model)) return false
|
|
134
|
+
if (excludeNameSet.has(i.as)) return false
|
|
131
135
|
return (
|
|
132
|
-
(
|
|
133
|
-
return app.model[m] !== i.model
|
|
134
|
-
}) ||
|
|
135
|
-
i.as) &&
|
|
136
|
+
(!excludeModelSet.has(i.model) || i.as) &&
|
|
136
137
|
!(
|
|
137
138
|
i.as &&
|
|
138
139
|
data.attributes &&
|
|
@@ -254,7 +255,9 @@ exports.initData = async ({ includes, excludes, app, ctx }) => {
|
|
|
254
255
|
}).then((res) => {
|
|
255
256
|
app.cache && app.cache.set(`${model}`, res)
|
|
256
257
|
const cacheModel = lodash.get(app, 'appConfig.cacheModel', [])
|
|
257
|
-
|
|
258
|
+
if (!cacheModel.includes(model)) {
|
|
259
|
+
app.appConfig.cacheModel = [...cacheModel, model]
|
|
260
|
+
}
|
|
258
261
|
return {
|
|
259
262
|
[item]: res,
|
|
260
263
|
}
|
|
@@ -275,14 +278,24 @@ exports.initData = async ({ includes, excludes, app, ctx }) => {
|
|
|
275
278
|
}
|
|
276
279
|
}
|
|
277
280
|
|
|
281
|
+
const settingById = new Map()
|
|
282
|
+
const codeCount = new Map()
|
|
283
|
+
for (const s of obj.setting) {
|
|
284
|
+
settingById.set(s.id, s)
|
|
285
|
+
codeCount.set(s.code, (codeCount.get(s.code) || 0) + 1)
|
|
286
|
+
}
|
|
287
|
+
|
|
278
288
|
return {
|
|
279
289
|
...obj,
|
|
280
290
|
setting: obj.setting.map((i) => {
|
|
281
291
|
let reset = true
|
|
282
292
|
if (i.parent_id) {
|
|
283
|
-
const parent =
|
|
284
|
-
|
|
285
|
-
|
|
293
|
+
const parent = settingById.get(i.parent_id)
|
|
294
|
+
if (
|
|
295
|
+
parent &&
|
|
296
|
+
parent.code !== config &&
|
|
297
|
+
(codeCount.get(i.code) || 0) > 1
|
|
298
|
+
) {
|
|
286
299
|
reset = false
|
|
287
300
|
}
|
|
288
301
|
}
|