q-koa 8.2.2 → 8.3.1
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.
|
@@ -5,6 +5,11 @@ const { VM } = require('vm2')
|
|
|
5
5
|
const axios = require('axios')
|
|
6
6
|
const cheerio = require('cheerio')
|
|
7
7
|
const { lodash, getAppByCtx, getConfig, Sequelize } = require('q-koa')
|
|
8
|
+
const LRU = require('lru-cache')
|
|
9
|
+
const cache = new LRU({
|
|
10
|
+
max: 10,
|
|
11
|
+
maxAge: 1000 * 60 * 60,
|
|
12
|
+
})
|
|
8
13
|
|
|
9
14
|
exports.initModel = async (ctx) => {
|
|
10
15
|
const { app } = getAppByCtx(ctx)
|
|
@@ -306,14 +311,27 @@ exports.showAllSchemas = async (ctx) => {
|
|
|
306
311
|
|
|
307
312
|
exports.initDataWithCache = exports.initData = async (ctx) => {
|
|
308
313
|
const { app } = getAppByCtx(ctx)
|
|
314
|
+
const appConfig = getConfig(app)
|
|
315
|
+
|
|
316
|
+
const { is_cache } = await appConfig.getObject('base')
|
|
309
317
|
const { includes, excludes = [] } = ctx.request.body
|
|
310
|
-
const result = await app.service.system.initData({
|
|
311
|
-
app,
|
|
312
|
-
includes,
|
|
313
|
-
excludes,
|
|
314
|
-
ctx,
|
|
315
|
-
})
|
|
316
318
|
|
|
319
|
+
const cacheTarget = JSON.stringify(ctx.request.body)
|
|
320
|
+
|
|
321
|
+
let result = null
|
|
322
|
+
if (is_cache && cache.get(cacheTarget)) {
|
|
323
|
+
result = cache.get(cacheTarget)
|
|
324
|
+
} else {
|
|
325
|
+
result = await app.service.system.initData({
|
|
326
|
+
app,
|
|
327
|
+
includes,
|
|
328
|
+
excludes,
|
|
329
|
+
ctx,
|
|
330
|
+
})
|
|
331
|
+
if (is_cache && cacheTarget.includes('setting/findAll')) {
|
|
332
|
+
cache.set(cacheTarget, result)
|
|
333
|
+
}
|
|
334
|
+
}
|
|
317
335
|
return ctx.SUCCESS(result)
|
|
318
336
|
}
|
|
319
337
|
|