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

Add pxtarget.json options for tuning time machine intervals #9786

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions localtypings/pxtarget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ declare namespace pxt {
timeMachine?: boolean; // Save/restore old versions of a project experiment
blocklySoundVolume?: number; // A number between 0 and 1 that sets the volume for blockly sounds (e.g. connect, disconnect, click)
timeMachineQueryParams?: string[]; // An array of query params to pass to timemachine iframe embed
timeMachineDiffInterval?: number; // An interval in milliseconds at which to take diffs to store in project history. Defaults to 5 minutes
timeMachineSnapshotInterval?: number; // An interval in milliseconds at which to take full project snapshots in project history. Defaults to 15 minutes
}

interface DownloadDialogTheme {
Expand Down
30 changes: 23 additions & 7 deletions pxteditor/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ namespace pxt.workspace {
maxTime?: number;
}

// 5 minutes
const DIFF_HISTORY_INTERVAL = 1000 * 60 * 5;
// 5 minutes. This is overridden in pxtarget.json
const DEFAULT_DIFF_HISTORY_INTERVAL = 1000 * 60 * 5;

// 15 minutes
const SNAPSHOT_HISTORY_INTERVAL = 1000 * 60 * 15;
// 15 minutes. This is overridden in pxtarget.json
const DEFAULT_SNAPSHOT_HISTORY_INTERVAL = 1000 * 60 * 15;

const ONE_DAY = 1000 * 60 * 60 * 24;

Expand Down Expand Up @@ -324,7 +324,7 @@ namespace pxt.workspace {
const topTime = history.entries[history.entries.length - 1].timestamp;
const prevTime = history.entries[history.entries.length - 2].timestamp;

if (currentTime - topTime < DIFF_HISTORY_INTERVAL && topTime - prevTime < DIFF_HISTORY_INTERVAL) {
if (currentTime - topTime < diffInterval() && topTime - prevTime < diffInterval()) {
shouldCombine = true;
}
}
Expand Down Expand Up @@ -352,7 +352,7 @@ namespace pxt.workspace {
if (history.snapshots.length == 0) {
history.snapshots.push(takeSnapshot(previousText, currentTime - 1));
}
else if (currentTime - history.snapshots[history.snapshots.length - 1].timestamp >= SNAPSHOT_HISTORY_INTERVAL) {
else if (currentTime - history.snapshots[history.snapshots.length - 1].timestamp >= snapshotInterval()) {
history.snapshots.push(takeSnapshot(previousText, currentTime));

const trimmed: pxt.workspace.SnapshotEntry[] = [];
Expand Down Expand Up @@ -441,4 +441,20 @@ namespace pxt.workspace {

return true;
}
}

function diffInterval() {
if (pxt.appTarget?.appTheme?.timeMachineDiffInterval != undefined) {
return pxt.appTarget.appTheme.timeMachineDiffInterval;
}

return DEFAULT_DIFF_HISTORY_INTERVAL;
}

function snapshotInterval() {
if (pxt.appTarget?.appTheme?.timeMachineSnapshotInterval != undefined) {
return pxt.appTarget.appTheme.timeMachineSnapshotInterval;
}

return DEFAULT_SNAPSHOT_HISTORY_INTERVAL;
}
}
Loading