1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

All: Resolves #10407: Added feature flag to disable sync lock support (#10925)

This commit is contained in:
Laurent Cozic 2024-08-23 12:16:19 +01:00 committed by GitHub
parent c691fedc12
commit b617a84696
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 0 deletions

View File

@ -131,6 +131,7 @@ export default class Synchronizer {
public lockHandler() {
if (this.lockHandler_) return this.lockHandler_;
this.lockHandler_ = new LockHandler(this.api());
this.lockHandler_.enabled = Setting.value('featureFlag.syncLockEnabled');
return this.lockHandler_;
}

View File

@ -1565,6 +1565,17 @@ const builtInMetadata = (Setting: typeof SettingType) => {
isGlobal: true,
},
'featureFlag.syncLockEnabled': {
value: true,
type: SettingItemType.Bool,
public: true,
storage: SettingStorage.File,
label: () => 'Enable sync locks',
description: () => 'This is an experimental setting to disable sync locks',
section: 'sync',
isGlobal: true,
},
// 'featureFlag.syncAccurateTimestamps': {
// value: false,

View File

@ -26,6 +26,16 @@ export interface Lock {
updatedTime?: number;
}
const nullLock = (): Lock => {
return {
clientId: '',
clientType: LockClientType.Desktop,
type: LockType.None,
id: 'NULL_LOCK',
updatedTime: Date.now(),
};
};
function lockIsActive(lock: Lock, currentDate: Date, lockTtl: number): boolean {
return currentDate.getTime() - lock.updatedTime < lockTtl;
}
@ -140,6 +150,7 @@ export default class LockHandler {
private refreshTimers_: RefreshTimers = {};
private autoRefreshInterval_: number = 1000 * 60;
private lockTtl_: number = defaultLockTtl;
private enabled_ = true;
public constructor(api: FileApi, options: LockHandlerOptions = null) {
if (!options) options = {};
@ -149,6 +160,14 @@ export default class LockHandler {
if ('autoRefreshInterval' in options) this.autoRefreshInterval_ = options.autoRefreshInterval;
}
public get enabled(): boolean {
return this.enabled_;
}
public set enabled(v: boolean) {
this.enabled_ = v;
}
public get lockTtl(): number {
return this.lockTtl_;
}
@ -185,6 +204,8 @@ export default class LockHandler {
}
public async locks(lockType: LockType = null): Promise<Lock[]> {
if (!this.enabled) return [];
if (this.useBuiltInLocks) {
const locks = (await this.api_.listLocks()).items;
return locks;
@ -352,6 +373,8 @@ export default class LockHandler {
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
public startAutoLockRefresh(lock: Lock, errorHandler: Function): string {
if (!this.enabled) return '';
const handle = this.autoLockRefreshHandle(lock);
if (this.refreshTimers_[handle]) {
throw new Error(`There is already a timer refreshing this lock: ${handle}`);
@ -409,6 +432,8 @@ export default class LockHandler {
}
public stopAutoLockRefresh(lock: Lock) {
if (!this.enabled) return;
const handle = this.autoLockRefreshHandle(lock);
if (!this.refreshTimers_[handle]) {
// Should not throw an error because lock may have been cleared in startAutoLockRefresh
@ -422,6 +447,8 @@ export default class LockHandler {
}
public async acquireLock(lockType: LockType, clientType: LockClientType, clientId: string, options: AcquireLockOptions = null): Promise<Lock> {
if (!this.enabled) return nullLock();
options = {
...defaultAcquireLockOptions(),
...options,
@ -437,6 +464,8 @@ export default class LockHandler {
}
public async releaseLock(lockType: LockType, clientType: LockClientType, clientId: string) {
if (!this.enabled) return;
if (this.useBuiltInLocks) {
await this.api_.releaseLock(lockType, clientType, clientId);
return;