refactor(backend): refactor chart engine
This commit is contained in:
parent
5c1d86b796
commit
7e63ab0f56
|
@ -459,13 +459,15 @@ export default abstract class Chart<T extends Schema> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bake unique count
|
// bake cardinality
|
||||||
for (const [k, v] of Object.entries(finalDiffs)) {
|
for (const [k, v] of Object.entries(finalDiffs)) {
|
||||||
if (this.schema[k].uniqueIncrement) {
|
if (this.schema[k].uniqueIncrement) {
|
||||||
const name = COLUMN_PREFIX + k.replaceAll('.', COLUMN_DELIMITER) as keyof Columns<T>;
|
const name = COLUMN_PREFIX + k.replaceAll('.', COLUMN_DELIMITER) as keyof Columns<T>;
|
||||||
const tempColumnName = UNIQUE_TEMP_COLUMN_PREFIX + k.replaceAll('.', COLUMN_DELIMITER) as keyof TempColumnsForUnique<T>;
|
const tempColumnName = UNIQUE_TEMP_COLUMN_PREFIX + k.replaceAll('.', COLUMN_DELIMITER) as keyof TempColumnsForUnique<T>;
|
||||||
queryForHour[name] = new Set([...(v as string[]), ...(logHour[tempColumnName] as unknown as string[])]).size;
|
const cardinalityOfHour = new Set([...(v as string[]), ...(logHour[tempColumnName] as unknown as string[])]).size;
|
||||||
queryForDay[name] = new Set([...(v as string[]), ...(logDay[tempColumnName] as unknown as string[])]).size;
|
const cardinalityOfDay = new Set([...(v as string[]), ...(logDay[tempColumnName] as unknown as string[])]).size;
|
||||||
|
queryForHour[name] = cardinalityOfHour;
|
||||||
|
queryForDay[name] = cardinalityOfDay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,7 +639,7 @@ export default abstract class Chart<T extends Schema> {
|
||||||
// 要求された範囲にログがひとつもなかったら
|
// 要求された範囲にログがひとつもなかったら
|
||||||
if (logs.length === 0) {
|
if (logs.length === 0) {
|
||||||
// もっとも新しいログを持ってくる
|
// もっとも新しいログを持ってくる
|
||||||
// (すくなくともひとつログが無いと隙間埋めできないため)
|
// (すくなくともひとつログが無いと補間できないため)
|
||||||
const recentLog = await repository.findOne({
|
const recentLog = await repository.findOne({
|
||||||
where: group ? {
|
where: group ? {
|
||||||
group: group,
|
group: group,
|
||||||
|
@ -654,7 +656,7 @@ export default abstract class Chart<T extends Schema> {
|
||||||
// 要求された範囲の最も古い箇所に位置するログが存在しなかったら
|
// 要求された範囲の最も古い箇所に位置するログが存在しなかったら
|
||||||
} else if (!isTimeSame(new Date(logs.at(-1)!.date * 1000), gt)) {
|
} else if (!isTimeSame(new Date(logs.at(-1)!.date * 1000), gt)) {
|
||||||
// 要求された範囲の最も古い箇所時点での最も新しいログを持ってきて末尾に追加する
|
// 要求された範囲の最も古い箇所時点での最も新しいログを持ってきて末尾に追加する
|
||||||
// (隙間埋めできないため)
|
// (補間できないため)
|
||||||
const outdatedLog = await repository.findOne({
|
const outdatedLog = await repository.findOne({
|
||||||
where: {
|
where: {
|
||||||
date: LessThan(Chart.dateToTimestamp(gt)),
|
date: LessThan(Chart.dateToTimestamp(gt)),
|
||||||
|
@ -683,7 +685,7 @@ export default abstract class Chart<T extends Schema> {
|
||||||
if (log) {
|
if (log) {
|
||||||
chart.unshift(this.convertRawRecord(log));
|
chart.unshift(this.convertRawRecord(log));
|
||||||
} else {
|
} else {
|
||||||
// 隙間埋め
|
// 補間
|
||||||
const latest = logs.find(l => isTimeBefore(new Date(l.date * 1000), current));
|
const latest = logs.find(l => isTimeBefore(new Date(l.date * 1000), current));
|
||||||
const data = latest ? this.convertRawRecord(latest) : null;
|
const data = latest ? this.convertRawRecord(latest) : null;
|
||||||
chart.unshift(this.getNewLog(data));
|
chart.unshift(this.getNewLog(data));
|
||||||
|
|
Loading…
Reference in New Issue