Improve chart engine (#8253)
* wip * wip * wip * wip * wip * wip * wip * Update core.ts * wip * wip * #7361 * delete network chart * federationChart強化 apRequestChart追加 * tweak
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../core';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { name, schema } from './entities/test';
|
||||
|
||||
type TestLog = SchemaType<typeof schema>;
|
||||
|
||||
/**
|
||||
* For testing
|
||||
*/
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default class TestChart extends Chart<TestLog> {
|
||||
export default class TestChart extends Chart<typeof schema> {
|
||||
public total = 0; // publicにするのはテストのため
|
||||
|
||||
constructor() {
|
||||
@@ -17,57 +14,29 @@ export default class TestChart extends Chart<TestLog> {
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: TestLog): DeepPartial<TestLog> {
|
||||
protected async queryCurrentState(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {
|
||||
foo: {
|
||||
total: latest.foo.total,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: TestLog[]): TestLog {
|
||||
return {
|
||||
foo: {
|
||||
total: logs[0].foo.total,
|
||||
inc: logs.reduce((a, b) => a + b.foo.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.foo.dec, 0),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<TestLog>> {
|
||||
return {
|
||||
foo: {
|
||||
total: this.total,
|
||||
},
|
||||
'foo.total': this.total,
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async increment(): Promise<void> {
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = 1;
|
||||
update.inc = 1;
|
||||
this.total++;
|
||||
|
||||
await this.inc({
|
||||
foo: update,
|
||||
await this.commit({
|
||||
'foo.total': 1,
|
||||
'foo.inc': 1,
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async decrement(): Promise<void> {
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = -1;
|
||||
update.dec = 1;
|
||||
this.total--;
|
||||
|
||||
await this.inc({
|
||||
foo: update,
|
||||
await this.commit({
|
||||
'foo.total': -1,
|
||||
'foo.dec': 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user