q-koa 9.7.2 → 9.7.4

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
@@ -294,6 +294,19 @@ class APP {
294
294
  process.on('exit', (code) => {
295
295
  console.log(`[exit custom], About to exit with code: ${code}`)
296
296
  })
297
+ if (this.app[appName].subscriber) {
298
+ try {
299
+ await this.app[appName].subscriber.subscribe(
300
+ 'cache clear',
301
+ (clearTarget) => {
302
+ this.app[appName].cache.set(clearTarget, null)
303
+ console.log(`subscribe cache clear ${clearTarget}`)
304
+ }
305
+ )
306
+ } catch (e) {
307
+ console.log('---<>', e.message)
308
+ }
309
+ }
297
310
  if (
298
311
  this.app[appName].service.cache &&
299
312
  this.app[appName].service.cache.init
@@ -361,9 +374,13 @@ class APP {
361
374
  client.on('error', (err) => console.log('Redis Client Error', err))
362
375
 
363
376
  await client.connect()
377
+
378
+ const subscriber = client.duplicate()
379
+ await subscriber.connect()
364
380
  this.app[appName] = {
365
381
  sequelize: db,
366
382
  redisClient: client,
383
+ subscriber,
367
384
  appConfig: _.defaultsDeep(
368
385
  configExist ? require(path.resolve(__dirname, configPath)) : {},
369
386
  this.config.app
@@ -1948,7 +1965,11 @@ APP.getConfig = (app) => ({
1948
1965
  return result
1949
1966
  },
1950
1967
  update() {
1951
- app.cache.set('configList', null)
1968
+ if (app.redisClient) {
1969
+ app.redisClient.publish('cache clear', 'configList')
1970
+ } else {
1971
+ app.cache.set('configList', null)
1972
+ }
1952
1973
  },
1953
1974
  })
1954
1975
 
@@ -0,0 +1,14 @@
1
+ const { getAppByCtx, getConfig } = require('q-koa')
2
+
3
+ exports.upsert = async (ctx) => {
4
+ const { app } = getAppByCtx(ctx)
5
+ const appConfig = getConfig(app)
6
+ appConfig.update()
7
+ }
8
+
9
+ exports.bulkUpdate = async (ctx) => {
10
+ const { app } = getAppByCtx(ctx)
11
+
12
+ const appConfig = getConfig(app)
13
+ appConfig.update()
14
+ }
@@ -0,0 +1,25 @@
1
+ module.exports = {
2
+ name: '应用配置',
3
+ belongs: 'page',
4
+ multiple: false,
5
+ availableSort: false,
6
+ order: [],
7
+ referenceSelect: [],
8
+ select: [],
9
+ excludes: [],
10
+ limit: 20,
11
+ defaultOrder: [],
12
+ comment: {},
13
+ sortOrder: 1,
14
+ reference: [],
15
+ excludeAuth: [],
16
+ initList: ['exclude_list', 'model'],
17
+ editInline: {},
18
+ autoData: {},
19
+ is_split: false,
20
+ is_split_count: false,
21
+ show_virtual: false,
22
+ modelQuery: {},
23
+ deleteCheckList: [],
24
+ bulkCreateList: [],
25
+ }
@@ -55,9 +55,10 @@ exports.getObject = (config, app) => async (type) => {
55
55
  const result = await app.model.application.findAll()
56
56
 
57
57
  if (result.length > 0) {
58
- app.cache.set('application', JSON.parse(JSON.stringify(result)))
58
+ const formatData = JSON.parse(JSON.stringify(result))
59
+ app.cache.set('application', formatData)
59
60
 
60
- const target = result.find(findConfig)
61
+ const target = formatData.find(findConfig)
61
62
  if (target) {
62
63
  flag = true
63
64
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "9.7.2",
3
+ "version": "9.7.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {