Skip to content

Commit 852c172

Browse files
committed
Apply collection level namespace config to dedicated channels
1 parent b2be29d commit 852c172

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

lib/mongo/Mutator.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default class Mutator {
7979
}
8080

8181
dispatchInsert(
82-
config.optimistic,
82+
config,
8383
this._name,
8484
config._channels,
8585
doc
@@ -196,7 +196,7 @@ export default class Mutator {
196196
const { fields } = getFields(modifier);
197197

198198
dispatchUpdate(
199-
config.optimistic,
199+
config,
200200
this._name,
201201
config._channels,
202202
docs,
@@ -259,7 +259,7 @@ export default class Mutator {
259259
}
260260

261261
dispatchInsert(
262-
config.optimistic,
262+
config,
263263
this._name,
264264
config._channels,
265265
doc
@@ -284,7 +284,7 @@ export default class Mutator {
284284
docs = this.find(selector).fetch();
285285

286286
dispatchUpdate(
287-
config.optimistic,
287+
config,
288288
this._name,
289289
config._channels,
290290
docs,
@@ -358,7 +358,7 @@ export default class Mutator {
358358
}
359359

360360
dispatchRemove(
361-
config.optimistic,
361+
config,
362362
this._name,
363363
config._channels,
364364
docs

lib/mongo/lib/dispatchers.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ import getDedicatedChannel from '../../utils/getDedicatedChannel';
88
import Config from '../../config';
99
import OptimisticInvocation from '../OptimisticInvocation';
1010

11-
const dispatchEvents = function(optimistic, collectionName, channels, events) {
11+
const dispatchEvents = function(config, collectionName, channels, events) {
12+
const { optimistic } = config;
1213
if (optimistic) {
1314
OptimisticInvocation.withValue(true, () => {
1415
events.forEach(event => {
1516
const docId = event[RedisPipe.DOC]._id;
16-
const dedicatedChannel = getDedicatedChannel(
17-
collectionName,
18-
docId
19-
);
17+
const dedicatedChannel = getDedicatedChannel(collectionName, docId, config);
2018
RedisSubscriptionManager.process(dedicatedChannel, event);
2119

2220
channels.forEach(channelName => {
@@ -37,20 +35,22 @@ const dispatchEvents = function(optimistic, collectionName, channels, events) {
3735
channels.forEach(channelName => {
3836
client.publish(channelName, message);
3937
});
38+
4039
const docId = event[RedisPipe.DOC]._id;
41-
const dedicatedChannel = getDedicatedChannel(collectionName, docId);
40+
const dedicatedChannel = getDedicatedChannel(collectionName, docId, config);
4241
client.publish(dedicatedChannel, message);
4342
});
4443
});
4544
};
4645

4746
const dispatchUpdate = function(
48-
optimistic,
47+
config,
4948
collectionName,
5049
channels,
5150
docs,
5251
fields
5352
) {
53+
const { optimistic } = config;
5454
const uid = optimistic ? RedisSubscriptionManager.uid : null;
5555

5656
const events = docs.map(doc => ({
@@ -60,10 +60,11 @@ const dispatchUpdate = function(
6060
[RedisPipe.UID]: uid,
6161
}));
6262

63-
dispatchEvents(optimistic, collectionName, channels, events);
63+
dispatchEvents(config, collectionName, channels, events);
6464
};
6565

66-
const dispatchRemove = function(optimistic, collectionName, channels, docs) {
66+
const dispatchRemove = function(config, collectionName, channels, docs) {
67+
const { optimistic } = config;
6768
const uid = optimistic ? RedisSubscriptionManager.uid : null;
6869

6970
const events = docs.map(doc => ({
@@ -72,10 +73,11 @@ const dispatchRemove = function(optimistic, collectionName, channels, docs) {
7273
[RedisPipe.UID]: uid,
7374
}));
7475

75-
dispatchEvents(optimistic, collectionName, channels, events);
76+
dispatchEvents(config, collectionName, channels, events);
7677
};
7778

78-
const dispatchInsert = function(optimistic, collectionName, channels, doc) {
79+
const dispatchInsert = function(config, collectionName, channels, doc) {
80+
const { optimistic } = config;
7981
const uid = optimistic ? RedisSubscriptionManager.uid : null;
8082

8183
const event = {
@@ -84,7 +86,7 @@ const dispatchInsert = function(optimistic, collectionName, channels, doc) {
8486
[RedisPipe.UID]: uid,
8587
};
8688

87-
dispatchEvents(optimistic, collectionName, channels, [event]);
89+
dispatchEvents(config, collectionName, channels, [event]);
8890
};
8991

9092
export { dispatchInsert, dispatchUpdate, dispatchRemove };

lib/redis/RedisSubscriber.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class RedisSubscriber {
3939
this.observableCollection.selector
4040
);
4141

42-
return ids.map(id => getDedicatedChannel(collectionName, id));
42+
return ids.map(id => getDedicatedChannel(collectionName, id, this.observableCollection.options));
4343
default:
4444
throw new Meteor.Error(
4545
`Strategy could not be found: ${this.strategy}`

lib/utils/getDedicatedChannel.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { MongoID } from 'meteor/mongo-id';
22
import getChannelName from './getChannelName';
33

4-
export default function getDedicatedChannel(collectionName, docId){
5-
const channelName = `${collectionName}::${MongoID.idStringify(docId)}`;
4+
// TODO do we want to support the multiple `namespaces` config for dedicated channels?
5+
export default function getDedicatedChannel(collectionName, docId, { namespace }){
6+
const channelName = `${namespace ? (namespace + '::') : ''}${collectionName}::${MongoID.idStringify(docId)}`;
67
return getChannelName(channelName);
78
}

0 commit comments

Comments
 (0)