mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-03-13 20:51:41 -05:00
feat(SharedData): set: log number of subscriptions
This commit is contained in:
@@ -5,6 +5,7 @@ const { log } = require('../util/logger')
|
||||
const path = require('path')
|
||||
const fs = require('fs-extra')
|
||||
const { rcFolder } = require('../util/rcFolder')
|
||||
const stats = require('../util/stats')
|
||||
|
||||
/**
|
||||
* @typedef SharedData
|
||||
@@ -67,12 +68,16 @@ async function set ({ id, projectId, value, disk = false }, context) {
|
||||
updated: new Date()
|
||||
})
|
||||
|
||||
const stat = stats.get(`shared-data_${projectId}`, id)
|
||||
stat.value = 0
|
||||
context.pubsub.publish(channels.SHARED_DATA_UPDATED, {
|
||||
sharedDataUpdated: { id, projectId, value }
|
||||
})
|
||||
|
||||
const watchers = notify({ id, projectId, value }, context)
|
||||
log('SharedData set', id, projectId, value, `(${watchers.length} watchers)`)
|
||||
|
||||
setTimeout(() => log('SharedData set', id, projectId, value, `(${watchers.length} watchers, ${stat.value} subscriptions)`))
|
||||
|
||||
return { id, value }
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ const files = require('./connectors/files')
|
||||
const clientAddons = require('./connectors/client-addons')
|
||||
const sharedData = require('./connectors/shared-data')
|
||||
const locales = require('./connectors/locales')
|
||||
// Utils
|
||||
const stats = require('./util/stats')
|
||||
// Start ipc server
|
||||
require('./util/ipc')
|
||||
|
||||
@@ -69,7 +71,13 @@ const resolvers = [{
|
||||
sharedDataUpdated: {
|
||||
subscribe: withFilter(
|
||||
(parent, args, { pubsub }) => pubsub.asyncIterator(channels.SHARED_DATA_UPDATED),
|
||||
(payload, vars) => payload.sharedDataUpdated.id === vars.id && payload.sharedDataUpdated.projectId === vars.projectId
|
||||
(payload, vars) => {
|
||||
const result = payload.sharedDataUpdated.id === vars.id && payload.sharedDataUpdated.projectId === vars.projectId
|
||||
if (result) {
|
||||
stats.get(`shared-data_${vars.projectId}`, vars.id).value++
|
||||
}
|
||||
return result
|
||||
}
|
||||
)
|
||||
},
|
||||
localeAdded: {
|
||||
|
||||
17
packages/@vue/cli-ui/apollo-server/util/stats.js
Normal file
17
packages/@vue/cli-ui/apollo-server/util/stats.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const stats = new Map()
|
||||
|
||||
exports.get = (type, id) => {
|
||||
let dic = stats.get(type)
|
||||
if (!dic) {
|
||||
dic = new Map()
|
||||
stats.set(type, dic)
|
||||
}
|
||||
let stat = dic.get(id)
|
||||
if (!stat) {
|
||||
stat = {
|
||||
value: 0
|
||||
}
|
||||
dic.set(id, stat)
|
||||
}
|
||||
return stat
|
||||
}
|
||||
Reference in New Issue
Block a user