Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compress changeFrame events #7048

Merged
merged 12 commits into from
Nov 2, 2023
1 change: 1 addition & 0 deletions cvat-core/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export default function logFactory(logType: LogType, payload: any): EventLogger
LogType.copyObject,
LogType.undoAction,
LogType.redoAction,
LogType.changeFrame,
];

if (logsWithCount.includes(logType)) {
Expand Down
49 changes: 40 additions & 9 deletions cvat-core/src/logger-storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2019-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
// Copyright (C) 2022-2023 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -15,40 +15,70 @@ function sleep(ms): Promise<void> {
});
}

function defaultUpdate(previousLog: EventLogger, currentPayload: any): object {
return {
...previousLog.payload,
...currentPayload,
};
}

interface IgnoreRule {
lastLog: EventLogger | null;
timeThreshold?: number;
ignore: (previousLog: EventLogger, currentPayload: any) => boolean;
update: (previousLog: EventLogger, currentPayload: any) => object;
}

type IgnoredRules = LogType.zoomImage | LogType.changeAttribute | LogType.changeFrame;

class LoggerStorage {
public clientID: string;
public collection: Array<EventLogger>;
public ignoreRules: Record<LogType.zoomImage | LogType.changeAttribute, IgnoreRule>;
public ignoreRules: Record<IgnoredRules, IgnoreRule>;
public isActiveChecker: (() => boolean) | null;
public saving: boolean;
private closeOnLog: Array<LogType>;

constructor() {
this.clientID = Date.now().toString().substr(-6);
this.collection = [];
this.isActiveChecker = null;
this.saving = false;
this.closeOnLog = [LogType.changeFrame];
this.ignoreRules = {
[LogType.zoomImage]: {
lastLog: null,
timeThreshold: 1000,
ignore(previousLog: EventLogger) {
timeThreshold: 4000,
ignore(previousLog: EventLogger): boolean {
return (Date.now() - previousLog.time.getTime()) < this.timeThreshold;
},
update: defaultUpdate,
},
[LogType.changeAttribute]: {
lastLog: null,
ignore(previousLog: EventLogger, currentPayload: any) {
ignore(previousLog: EventLogger, currentPayload: any): boolean {
return (
currentPayload.object_id === previousLog.payload.object_id &&
currentPayload.id === previousLog.payload.id
);
},
update: defaultUpdate,
},
[LogType.changeFrame]: {
lastLog: null,
ignore(previousLog: EventLogger, currentPayload: any): boolean {
nmanovic marked this conversation as resolved.
Show resolved Hide resolved
return (
currentPayload.job_id === previousLog.payload.job_id &&
currentPayload.step === previousLog.payload.step
);
},
update(previousLog: EventLogger, currentPayload: any): object {
return {
...previousLog.payload,
to: currentPayload.to,
count: previousLog.payload.count + 1,
};
},
},
};
}
Expand Down Expand Up @@ -109,10 +139,11 @@ Object.defineProperties(LoggerStorage.prototype.log, {
const ignoreRule = this.ignoreRules[logType];
const { lastLog } = ignoreRule;
if (lastLog && ignoreRule.ignore(lastLog, payload)) {
lastLog.payload = {
...lastLog.payload,
...payload,
};
lastLog.payload = ignoreRule.update(lastLog, payload);

if (this.closeOnLog.includes(logType)) {
await lastLog.close();
}
klakhov marked this conversation as resolved.
Show resolved Hide resolved

return ignoreRule.lastLog;
}
Expand Down
3 changes: 3 additions & 0 deletions cvat-ui/src/actions/annotation-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,9 @@ export function changeFrameAsync(
await job.logger.log(LogType.changeFrame, {
from: frame,
to: toFrame,
// step is passed with sign so we can know the direction
step: toFrame - frame,
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
count: 1,
});

const [minZ, maxZ] = computeZRange(states);
Expand Down
Loading