Small storage refactoring
This commit is contained in:
parent
625e7f9836
commit
a884fdaee7
@ -6,11 +6,10 @@ import { Executor } from './Executor';
|
||||
import { ControlPanel } from './ControlPanel';
|
||||
import { DataStorageTaskProvider } from './Queue/DataStorageTaskProvider';
|
||||
import { Statistics } from './Statistics';
|
||||
import { StatisticsStorage } from './Storage/StatisticsStorage';
|
||||
import { VillageRepository } from './VillageRepository';
|
||||
import { LogStorage } from './Storage/LogStorage';
|
||||
import { VillageFactory } from './VillageFactory';
|
||||
import { GrabberManager } from './Grabber/GrabberManager';
|
||||
import { StorageContainer } from './Storage/StorageContainer';
|
||||
|
||||
export class Container {
|
||||
private readonly version: string;
|
||||
@ -19,6 +18,13 @@ export class Container {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
private _storageContainer: StorageContainer | undefined;
|
||||
|
||||
get storageContainer(): StorageContainer {
|
||||
this._storageContainer = this._storageContainer || (() => new StorageContainer())();
|
||||
return this._storageContainer;
|
||||
}
|
||||
|
||||
private _villageRepository: VillageRepository | undefined;
|
||||
|
||||
get villageRepository(): VillageRepository {
|
||||
@ -36,7 +42,7 @@ export class Container {
|
||||
this._statistics =
|
||||
this._statistics ||
|
||||
(() => {
|
||||
return new Statistics(new StatisticsStorage());
|
||||
return new Statistics(this.storageContainer.statisticsStorage);
|
||||
})();
|
||||
return this._statistics;
|
||||
}
|
||||
@ -91,10 +97,12 @@ export class Container {
|
||||
this._executor =
|
||||
this._executor ||
|
||||
(() => {
|
||||
const logger = new AggregateLogger([
|
||||
new ConsoleLogger(Executor.name),
|
||||
new StorageLogger(new LogStorage(), LogLevel.warning),
|
||||
]);
|
||||
const consoleLogger = new ConsoleLogger(Executor.name);
|
||||
const storageLogger = new StorageLogger(
|
||||
this.storageContainer.logStorage,
|
||||
LogLevel.warning
|
||||
);
|
||||
const logger = new AggregateLogger([consoleLogger, storageLogger]);
|
||||
return new Executor(
|
||||
this.version,
|
||||
this.scheduler,
|
||||
|
@ -1,9 +1,9 @@
|
||||
import Vuex from 'vuex';
|
||||
import { LogStorage } from '../Storage/LogStorage';
|
||||
import { ReceiveResourcesMode, VillageSettings, VillageSettingsDefaults } from '../Core/Village';
|
||||
import { VillageSettings, VillageSettingsDefaults } from '../Core/Village';
|
||||
import { getNumber, notify } from '../utils';
|
||||
import { VillageStorage } from '../Storage/VillageStorage';
|
||||
import { VillageFactory } from '../VillageFactory';
|
||||
import { StorageContainer } from '../Storage/StorageContainer';
|
||||
|
||||
export enum Mutations {
|
||||
showLogs = 'showLogs',
|
||||
@ -107,7 +107,8 @@ export function createStore(villageFactory: VillageFactory) {
|
||||
});
|
||||
|
||||
setInterval(() => {
|
||||
const logStorage = new LogStorage();
|
||||
const stContainer = new StorageContainer();
|
||||
const logStorage = stContainer.logStorage;
|
||||
const logs = logStorage.getRecords();
|
||||
store.commit(Mutations.updateLogs, { logs });
|
||||
}, 1000);
|
||||
|
@ -1,15 +1,14 @@
|
||||
import { DataStorage } from '../DataStorage';
|
||||
import { LogStorageInterface, StorageLogRecord } from '../Logger';
|
||||
|
||||
const NAMESPACE = 'logs.v1';
|
||||
const RECORD_LIST_KEY = 'records';
|
||||
|
||||
const RECORD_COUNT = 200;
|
||||
|
||||
export class LogStorage implements LogStorageInterface {
|
||||
private storage: DataStorage;
|
||||
constructor() {
|
||||
this.storage = new DataStorage(NAMESPACE);
|
||||
private readonly storage: DataStorage;
|
||||
|
||||
constructor(storage: DataStorage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
write(record: StorageLogRecord): void {
|
||||
|
@ -1,14 +1,13 @@
|
||||
import { DataStorage } from '../DataStorage';
|
||||
import { ActionStatistics, StatisticsStorageInterface } from '../Statistics';
|
||||
|
||||
const NAMESPACE = 'statistics.v1';
|
||||
|
||||
const ACTION_STATISTICS_KEY = 'actions';
|
||||
|
||||
export class StatisticsStorage implements StatisticsStorageInterface {
|
||||
private storage: DataStorage;
|
||||
constructor() {
|
||||
this.storage = new DataStorage(NAMESPACE);
|
||||
|
||||
constructor(storage: DataStorage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
getActionStatistics(): ActionStatistics {
|
||||
|
20
src/Storage/StorageContainer.ts
Normal file
20
src/Storage/StorageContainer.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { LogStorage } from './LogStorage';
|
||||
import { DataStorage } from '../DataStorage';
|
||||
import { StatisticsStorage } from './StatisticsStorage';
|
||||
|
||||
export class StorageContainer {
|
||||
private _logStorage: LogStorage | undefined;
|
||||
|
||||
get logStorage(): LogStorage {
|
||||
this._logStorage = this._logStorage || new LogStorage(new DataStorage('logs.v1'));
|
||||
return this._logStorage;
|
||||
}
|
||||
|
||||
private _statisticsStorage: StatisticsStorage | undefined;
|
||||
|
||||
get statisticsStorage(): StatisticsStorage {
|
||||
this._statisticsStorage =
|
||||
this._statisticsStorage || new StatisticsStorage(new DataStorage('statistics.v1'));
|
||||
return this._statisticsStorage;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user