Skip to content

Commit

Permalink
Revert "Use web worker to throttle counts and schema changes (#6421)"
Browse files Browse the repository at this point in the history
This reverts commit 4687fbc.
  • Loading branch information
mantis-toboggan-md authored Jul 29, 2022
1 parent 3878303 commit 364a16d
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 293 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"ansi_up": "^5.0.0",
"babel-plugin-module-resolver": "^4.0.0",
"browser-env": "^3.2.6",
"comlink": "^4.3.1",
"cookie": "^0.4.0",
"cookie-universal-nuxt": "^2.0.17",
"cron-validator": "^1.2.0",
Expand Down Expand Up @@ -179,7 +178,6 @@
"vue-template-compiler": "2.6.14",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-virtual-modules": "^0.4.3",
"worker-loader": "^3.0.8",
"yaml-lint": "^1",
"yarn": "^1.22.11"
},
Expand Down
2 changes: 1 addition & 1 deletion shell/components/nav/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export default {
<div class="rd-header-right">
<HarvesterUpgrade v-if="isVirtualCluster && currentProduct.name === VIRTUAL" />
<div
v-if="(currentCluster || (currentProduct && currentProduct.customNamespaceFilter)) && !simple && (currentProduct.showNamespaceFilter || currentProduct.showWorkspaceSwitcher)"
v-if="(currentCluster || currentProduct.customNamespaceFilter) && !simple && (currentProduct.showNamespaceFilter || currentProduct.showWorkspaceSwitcher)"
class="top"
>
<NamespaceFilter v-if="clusterReady && currentProduct && (currentProduct.showNamespaceFilter || isExplorer)" />
Expand Down
2 changes: 0 additions & 2 deletions shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"babel-plugin-module-resolver": "^4.0.0",
"babel-preset-vue": "^2.0.2",
"browser-env": "^3.2.6",
"comlink": "^4.3.1",
"cookie": "^0.4.0",
"cookie-universal-nuxt": "^2.0.17",
"core-js": "^3.20.3",
Expand Down Expand Up @@ -149,7 +148,6 @@
"xterm-addon-search": "^0.7.0",
"xterm-addon-web-links": "^0.4.0",
"xterm-addon-webgl": "^0.9.0",
"worker-loader": "^3.0.8",
"yarn": "^1.22.11"
},
"nyc": {
Expand Down
70 changes: 34 additions & 36 deletions shell/plugins/dashboard-store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,46 @@ export async function handleSpoofedRequest(rootGetters, schemaStore, opt, produc
}
}

export async function loadSchemas(ctx, watch = true) {
const {
getters, dispatch, commit, rootGetters
} = ctx;
const res = await dispatch('findAll', { type: SCHEMA, opt: { url: 'schemas', load: false } });
const spoofedTypes = rootGetters['type-map/allSpoofedSchemas'] ;

if (Array.isArray(res.data)) {
res.data = res.data.concat(spoofedTypes);
} else if (Array.isArray(res)) {
res.data = res.concat(spoofedTypes);
}
export default {
request() {
throw new Error('Not Implemented');
},

res.data.forEach((schema) => {
schema._id = normalizeType(schema.id);
schema._group = normalizeType(schema.attributes?.group);
});

commit('loadAll', {
ctx,
type: SCHEMA,
data: res.data
});

if ( watch !== false ) {
dispatch('watch', {
type: SCHEMA,
revision: res.revision
async loadSchemas(ctx, watch = true) {
const {
getters, dispatch, commit, rootGetters
} = ctx;
const res = await dispatch('findAll', { type: SCHEMA, opt: { url: 'schemas', load: false } });
const spoofedTypes = rootGetters['type-map/allSpoofedSchemas'] ;

if (Array.isArray(res.data)) {
res.data = res.data.concat(spoofedTypes);
} else if (Array.isArray(res)) {
res.data = res.concat(spoofedTypes);
}

res.data.forEach((schema) => {
schema._id = normalizeType(schema.id);
schema._group = normalizeType(schema.attributes?.group);
});
}

const all = getters.all(SCHEMA);
commit('loadAll', {
ctx,
type: SCHEMA,
data: res.data
});

return all;
}
if ( watch !== false ) {
dispatch('watch', {
type: SCHEMA,
revision: res.revision
});
}

export default {
request() {
throw new Error('Not Implemented');
},
const all = getters.all(SCHEMA);

loadSchemas,
return all;
},

async findAll(ctx, { type, opt }) {
const {
Expand Down
6 changes: 1 addition & 5 deletions shell/plugins/dashboard-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const coreStoreState = (namespace, baseUrl, isClusterStore) => ({
types: {},
});

export default (vuexModule, config, init) => {
export default (vuexModule, config) => {
const namespace = config.namespace || '';

return function(store) {
Expand Down Expand Up @@ -61,10 +61,6 @@ export default (vuexModule, config, init) => {
}
});

if (init) {
init(store, ctx);
}

// Turn all the objects in the store from the server into proxies
const state = fromServer?.state?.[namespace];

Expand Down
8 changes: 1 addition & 7 deletions shell/plugins/steve/actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import https from 'https';
import { addParam, parse as parseUrl, stringify as unParseUrl } from '@shell/utils/url';
import { handleSpoofedRequest, loadSchemas } from '@shell/plugins/dashboard-store/actions';
import { handleSpoofedRequest } from '@shell/plugins/dashboard-store/actions';
import { set } from '@shell/utils/object';
import { deferred } from '@shell/utils/promise';
import { streamJson, streamingSupported } from '@shell/utils/stream';
Expand All @@ -9,12 +9,6 @@ import { classify } from '@shell/plugins/dashboard-store/classify';
import { NAMESPACE } from '@shell/config/types';

export default {

// Need to override this, so that thhe 'this' context is correct (this class not the base class)
async loadSchemas(ctx, watch = true) {
return await loadSchemas(ctx, watch);
},

async request({ state, dispatch, rootGetters }, pOpt ) {
const opt = pOpt.opt || pOpt;

Expand Down
7 changes: 2 additions & 5 deletions shell/plugins/steve/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import coreStore, { coreStoreModule, coreStoreState } from '@shell/plugins/dashboard-store/index';

import {
createWorker,
mutations as subscribeMutations,
actions as subscribeActions,
getters as subscribeGetters
Expand Down Expand Up @@ -65,10 +65,7 @@ export default (config) => {
}

return coreStore(
SteveFactory(config.namespace, config.baseUrl),
SteveFactory(config),
config,
(store, ctx) => {
createWorker(store, ctx);
}
);
};
12 changes: 1 addition & 11 deletions shell/plugins/steve/mutations.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addObject, removeObject } from '@shell/utils/array';
import { NAMESPACE, POD, SCHEMA } from '@shell/config/types';
import { NAMESPACE, POD } from '@shell/config/types';
import {
forgetType,
resetStore,
Expand Down Expand Up @@ -52,16 +52,6 @@ export default {
cache.map.set(entry.id, entry);
});
}

// Notify the web worker of the initial load of schemas
if (type === SCHEMA) {
const worker = (this.$workers || {})[ctx.getters.storeName];

if (worker) {
// Store raw json objects, not the proxies
worker.loadSchema(data);
}
}
},

forgetType(state, type) {
Expand Down
88 changes: 6 additions & 82 deletions shell/plugins/steve/subscribe.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { addObject, clear, removeObject } from '@shell/utils/array';
import { get } from '@shell/utils/object';
import { COUNT, SCHEMA } from '@shell/config/types';
import Socket, {
EVENT_CONNECTED,
EVENT_DISCONNECTED,
Expand All @@ -14,10 +13,6 @@ import day from 'dayjs';
import { DATE_FORMAT, TIME_FORMAT } from '@shell/store/prefs';
import { escapeHtml } from '@shell/utils/string';

// eslint-disable-next-line
import Worker from 'worker-loader!./worker'
import * as Comlink from 'comlink';

export const NO_WATCH = 'NO_WATCH';
export const NO_SCHEMA = 'NO_SCHEMA';

Expand All @@ -27,30 +22,6 @@ const MINIMUM_TIME_NOTIFIED = 3000;
// minimum time a socket must be disconnected for before sending a growl
const MINIMUM_TIME_DISCONNECTED = 10000;

// We only create a worker for the cluster store
export function createWorker(store, ctx) {
const { getters } = ctx;
const storeName = getters.storeName;

store.$workers = store.$workers || {};

if (storeName !== 'cluster') {
return;
}

function callback(resource) {
queueChange(ctx, resource, true, 'Change');
}

if (!store.$workers[storeName]) {
const worker = Comlink.wrap(new Worker());

store.$workers[storeName] = worker;

worker.initWorker(storeName, Comlink.proxy(callback));
}
}

export function keyForSubscribe({
resourceType, type, namespace, id, selector
} = {}) {
Expand Down Expand Up @@ -107,7 +78,7 @@ function queueChange({ getters, state }, { data, revision }, load, label) {
});
}

if ( type === SCHEMA ) {
if ( type === 'schema' ) {
// Clear the current records in the store when a type disappears
state.queue.push({
action: 'commit',
Expand Down Expand Up @@ -179,23 +150,11 @@ export const actions = {
socket.connect(get(opt, 'metadata'));
},

unsubscribe({ state, commit, getters }) {
unsubscribe({ state, commit }) {
const socket = state.socket;
const worker = (this.$workers || {})[getters.storeName];

commit('setWantSocket', false);

if (worker) {
try {
worker.destroyWorker();
worker[Comlink.releaseProxy]();
} catch (e) {
console.error(e); // eslint-disable-line no-console
}

delete this.$workers[getters.storeName];
}

if ( socket ) {
return socket.disconnect();
}
Expand Down Expand Up @@ -564,36 +523,10 @@ export const actions = {
},

'ws.resource.change'(ctx, msg) {
const data = msg.data;
const type = data.type;

// Debounce count changes so we send at most 1 every 5 seconds
if (type === COUNT) {
const worker = (this.$workers || {})[ctx.getters.storeName];

if (worker) {
worker.countsUpdate(msg);

// No further processing - let the web worker debounce the counts
return;
}
}

// Web worker can process schemas to check that they are actually changing and
// only load updates if the schema did actually change
if (type === SCHEMA) {
const worker = (this.$workers || {})[ctx.getters.storeName];

if (worker) {
worker.updateSchema(data);

// No further processing - let the web worker check the schema updates
return;
}
}

queueChange(ctx, msg, true, 'Change');

const data = msg.data;
const type = data.type;
const typeOption = ctx.rootGetters['type-map/optionsFor'](type);

if (typeOption?.alias?.length > 0) {
Expand All @@ -613,19 +546,10 @@ export const actions = {
},

'ws.resource.remove'(ctx, msg) {
const data = msg.data;
const type = data.type;

if (type === SCHEMA) {
const worker = (this.$workers || {})[ctx.getters.storeName];

if (worker) {
worker.removeSchema(data.id);
}
}

queueChange(ctx, msg, false, 'Remove');

const data = msg.data;
const type = data.type;
const typeOption = ctx.rootGetters['type-map/optionsFor'](type);

if (typeOption?.alias?.length > 0) {
Expand Down
Loading

0 comments on commit 364a16d

Please sign in to comment.