Мелкая оптимизация, чтобы не отдавал большой конфиг каждый раз при обновлении страницы
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
import wsc from './webSocketConnection';
|
import wsc from './webSocketConnection';
|
||||||
|
|
||||||
class Misc {
|
class Misc {
|
||||||
async loadConfig() {
|
async loadConfig(_configHash) {
|
||||||
|
|
||||||
const query = {params: [
|
const query = {
|
||||||
'name', 'version', 'mode', 'maxUploadFileSize', 'useExternalBookConverter',
|
params: [
|
||||||
'acceptFileExt', 'bucEnabled', 'branch', 'networkLibraryLink', 'restricted'
|
'name', 'version', 'mode', 'maxUploadFileSize', 'useExternalBookConverter',
|
||||||
]};
|
'acceptFileExt', 'bucEnabled', 'branch', 'networkLibraryLink', 'restricted'
|
||||||
|
],
|
||||||
|
_configHash,
|
||||||
|
};
|
||||||
|
|
||||||
const config = await wsc.message(await wsc.send(Object.assign({action: 'get-config'}, query)));
|
const config = await wsc.message(await wsc.send(Object.assign({action: 'get-config'}, query)));
|
||||||
if (config.error)
|
if (config.error)
|
||||||
|
|||||||
@@ -154,8 +154,11 @@ class App {
|
|||||||
(async() => {
|
(async() => {
|
||||||
//загрузим конфиг сервера
|
//загрузим конфиг сервера
|
||||||
try {
|
try {
|
||||||
const config = await miscApi.loadConfig();
|
const config = await miscApi.loadConfig(this.config._configHash);
|
||||||
this.commit('config/setConfig', config);
|
|
||||||
|
if (!config._useCached)
|
||||||
|
this.commit('config/setConfig', config);
|
||||||
|
|
||||||
this.showPage = true;
|
this.showPage = true;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
//проверим, не получен ли конфиг ранее
|
//проверим, не получен ли конфиг ранее
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import miscApi from '../../api/misc';
|
|
||||||
// initial state
|
// initial state
|
||||||
const state = {
|
const state = {
|
||||||
name: null,
|
name: null,
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ class WebSocketController {
|
|||||||
this.readerWorker = new ReaderWorker(config);
|
this.readerWorker = new ReaderWorker(config);
|
||||||
this.workerState = new WorkerState();
|
this.workerState = new WorkerState();
|
||||||
|
|
||||||
|
this.configHash = '';
|
||||||
|
|
||||||
if (config.bucEnabled) {
|
if (config.bucEnabled) {
|
||||||
this.bucClient = new BUCClient(config);
|
this.bucClient = new BUCClient(config);
|
||||||
}
|
}
|
||||||
@@ -119,8 +121,22 @@ class WebSocketController {
|
|||||||
async getConfig(req, ws) {
|
async getConfig(req, ws) {
|
||||||
if (Array.isArray(req.params)) {
|
if (Array.isArray(req.params)) {
|
||||||
const paramsSet = new Set(req.params);
|
const paramsSet = new Set(req.params);
|
||||||
|
const _configHash = req._configHash;
|
||||||
|
|
||||||
this.send(_.pick(this.config, this.config.webConfigParams.filter(x => paramsSet.has(x))), req, ws);
|
let response = {_useCached: true};
|
||||||
|
|
||||||
|
//оптимизация, чтобы не отдавал большой конфиг каждый раз при обновлении страницы
|
||||||
|
if (!_configHash || _configHash !== this.configHash) {
|
||||||
|
if (!this.configHash) {
|
||||||
|
const webConfig = _.pick(this.config, this.config.webConfigParams);
|
||||||
|
this.configHash = await utils.getBufHash(Buffer.from(JSON.stringify(webConfig)), 'sha256', 'hex');
|
||||||
|
}
|
||||||
|
|
||||||
|
response = _.pick(this.config, this.config.webConfigParams.filter(x => paramsSet.has(x)));
|
||||||
|
response._configHash = this.configHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.send(response, req, ws);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('params is not an array');
|
throw new Error('params is not an array');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user