Skip to content

Commit bdf74ba

Browse files
author
Guillaume Chau
committed
feat(SharedData): set: log number of subscriptions
1 parent 022e17d commit bdf74ba

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

packages/@vue/cli-ui/apollo-server/connectors/shared-data.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { log } = require('../util/logger')
55
const path = require('path')
66
const fs = require('fs-extra')
77
const { rcFolder } = require('../util/rcFolder')
8+
const stats = require('../util/stats')
89

910
/**
1011
* @typedef SharedData
@@ -67,12 +68,16 @@ async function set ({ id, projectId, value, disk = false }, context) {
6768
updated: new Date()
6869
})
6970

71+
const stat = stats.get(`shared-data_${projectId}`, id)
72+
stat.value = 0
7073
context.pubsub.publish(channels.SHARED_DATA_UPDATED, {
7174
sharedDataUpdated: { id, projectId, value }
7275
})
7376

7477
const watchers = notify({ id, projectId, value }, context)
75-
log('SharedData set', id, projectId, value, `(${watchers.length} watchers)`)
78+
79+
setTimeout(() => log('SharedData set', id, projectId, value, `(${watchers.length} watchers, ${stat.value} subscriptions)`))
80+
7681
return { id, value }
7782
}
7883

packages/@vue/cli-ui/apollo-server/resolvers.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const files = require('./connectors/files')
1212
const clientAddons = require('./connectors/client-addons')
1313
const sharedData = require('./connectors/shared-data')
1414
const locales = require('./connectors/locales')
15+
// Utils
16+
const stats = require('./util/stats')
1517
// Start ipc server
1618
require('./util/ipc')
1719

@@ -69,7 +71,13 @@ const resolvers = [{
6971
sharedDataUpdated: {
7072
subscribe: withFilter(
7173
(parent, args, { pubsub }) => pubsub.asyncIterator(channels.SHARED_DATA_UPDATED),
72-
(payload, vars) => payload.sharedDataUpdated.id === vars.id && payload.sharedDataUpdated.projectId === vars.projectId
74+
(payload, vars) => {
75+
const result = payload.sharedDataUpdated.id === vars.id && payload.sharedDataUpdated.projectId === vars.projectId
76+
if (result) {
77+
stats.get(`shared-data_${vars.projectId}`, vars.id).value++
78+
}
79+
return result
80+
}
7381
)
7482
},
7583
localeAdded: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const stats = new Map()
2+
3+
exports.get = (type, id) => {
4+
let dic = stats.get(type)
5+
if (!dic) {
6+
dic = new Map()
7+
stats.set(type, dic)
8+
}
9+
let stat = dic.get(id)
10+
if (!stat) {
11+
stat = {
12+
value: 0
13+
}
14+
dic.set(id, stat)
15+
}
16+
return stat
17+
}

0 commit comments

Comments
 (0)