Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.

Commit fa6dac6

Browse files
authored
Merge pull request #91 from kuzzleio/4.0.0-proposal
# [4.0.0](https://github.com/kuzzleio/kuzzle-plugin-cluster/releases/tag/4.0.0) (2019-09-19) #### Enhancements - [ [#85](#85) ] Adapt cluster for the new indexCache ([Aschen](https://github.com/Aschen)) - [ [#84](#84) ] Remove the deprecated notifications state ([scottinet](https://github.com/scottinet)) ---
2 parents d55ecb6 + 8aa9e7b commit fa6dac6

File tree

9 files changed

+916
-837
lines changed

9 files changed

+916
-837
lines changed

.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,9 @@
5454
"node": true,
5555
"es6": true
5656
},
57+
"parserOptions": {
58+
"sourceType": "module",
59+
"ecmaVersion": 2018
60+
},
5761
"extends": "eslint:recommended"
5862
}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM kuzzleio/kuzzle
1+
FROM kuzzleio/kuzzle:1.10.2
22

33
LABEL "io.kuzzle.vendor"="Kuzzle"
44

lib/index.js

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class KuzzleCluster {
4343
*/
4444
constructor () {
4545
this.config = null;
46-
/** @type {PluginContext} */
4746
this.context = null;
4847
this.kuzzle = null;
4948
this.uuid = null;
@@ -55,7 +54,6 @@ class KuzzleCluster {
5554
'core:kuzzleStart': 'kuzzleStarted',
5655
'core:indexCache:add': 'indexCacheAdded',
5756
'core:indexCache:remove': 'indexCacheRemoved',
58-
'core:indexCache:reset': 'indexCacheReset',
5957
'core:notify:document': 'notifyDocument',
6058
'core:notify:user': 'notifyUser',
6159
'core:hotelClerk:addSubscription': 'subscriptionAdded',
@@ -65,7 +63,6 @@ class KuzzleCluster {
6563
'core:profileRepository:delete': 'profileUpdated',
6664
'core:roleRepository:save': 'roleUpdated',
6765
'core:roleRepository:delete': 'roleUpdated',
68-
'index:afterSetAutoRefresh': 'autoRefreshUpdated',
6966
'collection:afterUpdateSpecifications': 'refreshSpecifications',
7067
'collection:afterDeleteSpecifications': 'refreshSpecifications',
7168
'realtime:errorSubscribe': 'unlockCreateRoom',
@@ -168,21 +165,6 @@ class KuzzleCluster {
168165
// hooks
169166
// --------------------------------------------------------------------------
170167

171-
/**
172-
* @param {Request} request
173-
*/
174-
autoRefreshUpdated (request) {
175-
if (!this.node.ready) {
176-
debug('[%s][warning] could not broadcast "autoRefresh updated" action: node not connected to cluster', this.uuid);
177-
return;
178-
}
179-
180-
return this.redis.hset('cluster:autorefresh', request.input.resource.index, request.input.body.autoRefresh)
181-
.then(() => this.node.broadcast('cluster:sync', {
182-
event: 'autorefresh'
183-
}));
184-
}
185-
186168
/**
187169
* @param {Request} request
188170
* @param {function} cb callback
@@ -222,45 +204,36 @@ class KuzzleCluster {
222204
}
223205

224206
/**
225-
* @param {object} diff
207+
* Hook for core:indexCache:add
208+
*
209+
* @param {Object} payload - { index, collection, scope }
226210
*/
227-
indexCacheAdded (diff) {
211+
indexCacheAdded (payload) {
228212
if (!this.node.ready) {
229213
debug('[%s][warning] could not broadcast "index cache added" action: node not connected to cluster', this.uuid);
230214
return;
231215
}
232216

233217
this.node.broadcast('cluster:sync', {
234218
event: 'indexCache:add',
235-
index: diff.index,
236-
collection: diff.collection
219+
...payload
237220
});
238221
}
239222

240223
/**
241-
* @param {object} diff
224+
* Hook for core:indexCache:remove
225+
*
226+
* @param {Object} payload - { index, collection, scope }
242227
*/
243-
indexCacheRemoved (diff) {
228+
indexCacheRemoved (payload) {
244229
if (!this.node.ready) {
245230
debug('[%s][warning] could not broadcast "index cache removed" action: node not connected to cluster', this.uuid);
246231
return;
247232
}
248233

249234
this.node.broadcast('cluster:sync', {
250235
event: 'indexCache:remove',
251-
index: diff.index,
252-
collection: diff.collection
253-
});
254-
}
255-
256-
indexCacheReset () {
257-
if (!this.node.ready) {
258-
debug('[%s][warning] could not broadcast "index cache reseted" action: node not connected to cluster', this.uuid);
259-
return;
260-
}
261-
262-
this.node.broadcast('cluster:sync', {
263-
event: 'indexCache:reset'
236+
...payload
264237
});
265238
}
266239

lib/node.js

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -181,28 +181,21 @@ class Node {
181181
}
182182

183183
switch (data.event) {
184-
case 'autorefresh':
185-
return this.redis
186-
.hgetall('cluster:autorefresh')
187-
.then(autoRefreshes => {
188-
for (const index of Object.keys(autoRefreshes)) {
189-
const autoRefresh = autoRefreshes[index];
190-
this.kuzzle.services.list.storageEngine.setAutoRefresh(new Request({
191-
index,
192-
controller: 'index',
193-
action: 'setAutoRefresh',
194-
body: {autoRefresh}
195-
}));
196-
}
197-
});
198184
case 'indexCache:add':
199-
this.kuzzle.indexCache.add(data.index, data.collection, false);
185+
this.kuzzle.storageEngine.indexCache.add({
186+
index: data.index,
187+
collection: data.collection,
188+
scope: data.scope,
189+
notify: false
190+
});
200191
break;
201192
case 'indexCache:remove':
202-
this.kuzzle.indexCache.remove(data.index, data.collection, false);
203-
break;
204-
case 'indexCache:reset':
205-
this.kuzzle.indexCache.reset();
193+
this.kuzzle.storageEngine.indexCache.remove({
194+
index: data.index,
195+
collection: data.collection,
196+
scope: data.scope,
197+
notify: false
198+
});
206199
break;
207200
case 'profile':
208201
delete this.kuzzle.repositories.profile.profiles[data.id];
@@ -400,7 +393,6 @@ class Node {
400393
data.rooms,
401394
new Request(data.request.data, data.request.options),
402395
data.scope,
403-
data.state,
404396
data.action,
405397
data.content
406398
);

0 commit comments

Comments
 (0)