New OO checkpoints

pull/1/head
yflory 3 years ago
parent eee79e5553
commit b896870632

@ -56,11 +56,12 @@ define([
urlArgs: Util.find(ApiConfig, ['requireConf', 'urlArgs']) urlArgs: Util.find(ApiConfig, ['requireConf', 'urlArgs'])
}; };
var CHECKPOINT_INTERVAL = 100; var CHECKPOINT_INTERVAL = 20;
var FORCE_CHECKPOINT_INTERVAL = 50;
var DISPLAY_RESTORE_BUTTON = false; var DISPLAY_RESTORE_BUTTON = false;
var NEW_VERSION = 4; var NEW_VERSION = 4; // version of the .bin, patches and ChainPad formats
var PENDING_TIMEOUT = 30000; var PENDING_TIMEOUT = 30000;
var CURRENT_VERSION = 'v4'; var CURRENT_VERSION = 'v4'; // Path to the current onlyoffice version
//var READONLY_REFRESH_TO = 15000; //var READONLY_REFRESH_TO = 15000;
var debug = function (x, type) { var debug = function (x, type) {
@ -478,6 +479,9 @@ define([
delete APP.refreshPopup; delete APP.refreshPopup;
clearTimeout(APP.refreshRoTo); clearTimeout(APP.refreshRoTo);
// Don't create the initial checkpoint indefinitely in a loop
delete APP.initCheckpoint;
if (!isLockedModal.modal) { if (!isLockedModal.modal) {
isLockedModal.modal = UI.openCustomModal(isLockedModal.content); isLockedModal.modal = UI.openCustomModal(isLockedModal.content);
} }
@ -539,8 +543,9 @@ define([
var locked = content.saveLock; var locked = content.saveLock;
var lastCp = getLastCp(); var lastCp = getLastCp();
var needCp = force || ooChannel.cpIndex % CHECKPOINT_INTERVAL === 0 || var currentIdx = ooChannel.cpIndex;
(ooChannel.cpIndex - (lastCp.index || 0)) > CHECKPOINT_INTERVAL; var needCp = force || (currentIdx - (lastCp.index || 0)) > FORCE_CHECKPOINT_INTERVAL;
if (!needCp) { return; } if (!needCp) { return; }
if (!locked || !isUserOnline(locked) || force) { if (!locked || !isUserOnline(locked) || force) {
@ -1526,10 +1531,15 @@ define([
} catch (e) {} } catch (e) {}
} }
if (lock && !readOnly) { if (lock && !readOnly) { // Lock = !history && migrate
onMigrateRdy.fire(); onMigrateRdy.fire();
} }
if (APP.initCheckpoint) {
getEditor().asc_setRestriction(true);
makeCheckpoint(true);
}
// Check if history can/should be trimmed // Check if history can/should be trimmed
var cp = getLastCp(); var cp = getLastCp();
if (cp && cp.file && cp.hash) { if (cp && cp.file && cp.hash) {
@ -2729,6 +2739,21 @@ define([
oldHashes = JSON.parse(JSON.stringify(content.hashes)); oldHashes = JSON.parse(JSON.stringify(content.hashes));
initializing = false; initializing = false;
// If we have more than CHECKPOINT_INTERVAL patches in the initial history
// and we're the only editor in the pad, make a checkpoint
var userData = metadataMgr.getMetadata().users;
var v = metadataMgr.getViewers();
var m = metadataMgr.getChannelMembers().filter(function (str) {
return str.length === 32;
}).length;
if ((m - v) === 1 && !readOnly) {
var l = ooChannel.queue.length;
var lastCp = getLastCp();
var needCp = ooChannel.queue.length > CHECKPOINT_INTERVAL;
APP.initCheckpoint = needCp;
}
common.openPadChat(APP.onLocal); common.openPadChat(APP.onLocal);
if (!readOnly) { if (!readOnly) {

Loading…
Cancel
Save