server: use prelude function instead of separate function
All checks were successful
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-client Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-sw Pipeline was successful
ci/woodpecker/push/test Pipeline was successful

This commit is contained in:
Johann150 2022-12-23 13:55:15 +01:00
parent eaa11647f0
commit 85419326f8
Signed by: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -7,6 +7,7 @@
import * as nestedProperty from 'nested-property'; import * as nestedProperty from 'nested-property';
import { EntitySchema, Repository, LessThan, Between } from 'typeorm'; import { EntitySchema, Repository, LessThan, Between } from 'typeorm';
import { dateUTC, isTimeSame, isTimeBefore, subtractTime, addTime } from '@/prelude/time.js'; import { dateUTC, isTimeSame, isTimeBefore, subtractTime, addTime } from '@/prelude/time.js';
import { unique } from '@/prelude/array.js';
import { getChartInsertLock } from '@/misc/app-lock.js'; import { getChartInsertLock } from '@/misc/app-lock.js';
import { db } from '@/db/postgre.js'; import { db } from '@/db/postgre.js';
import Logger from '../logger.js'; import Logger from '../logger.js';
@ -56,8 +57,6 @@ const camelToSnake = (str: string): string => {
return str.replace(/([A-Z])/g, s => '_' + s.charAt(0).toLowerCase()); return str.replace(/([A-Z])/g, s => '_' + s.charAt(0).toLowerCase());
}; };
const removeDuplicates = (array: any[]) => Array.from(new Set(array));
type Commit<S extends Schema> = { type Commit<S extends Schema> = {
[K in keyof S]?: S[K]['uniqueIncrement'] extends true ? string[] : number; [K in keyof S]?: S[K]['uniqueIncrement'] extends true ? string[] : number;
}; };
@ -483,7 +482,7 @@ export default abstract class Chart<T extends Schema> {
this.buffer = this.buffer.filter(q => q.group != null && (q.group !== logHour.group)); this.buffer = this.buffer.filter(q => q.group != null && (q.group !== logHour.group));
}; };
const groups = removeDuplicates(this.buffer.map(log => log.group)); const groups = unique(this.buffer.map(log => log.group));
await Promise.all( await Promise.all(
groups.map(group => groups.map(group =>
@ -651,12 +650,7 @@ export default abstract class Chart<T extends Schema> {
const res = {} as ChartResult<T>; const res = {} as ChartResult<T>;
/** // Turn array of objects into object of arrays.
* Turn
* [{ foo: 1, bar: 5 }, { foo: 2, bar: 6 }, { foo: 3, bar: 7 }]
* into
* { foo: [1, 2, 3], bar: [5, 6, 7] }
*/
for (const record of chart) { for (const record of chart) {
for (const [k, v] of Object.entries(record) as ([keyof typeof record, number])[]) { for (const [k, v] of Object.entries(record) as ([keyof typeof record, number])[]) {
if (res[k]) { if (res[k]) {