mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 13:25:11 +00:00
Prevent Desktop app triggering multiple simultaneous syncs to server
Lock syncing to server if a sync is already in progress. While the sync save button gets disabled while sync is in progress, the background sync job can still trigger a sync in parallel. This sync lock prevents that
This commit is contained in:
@@ -110,6 +110,15 @@ function filenameToMimeType (filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function pushDataToKhoj (regenerate = false) {
|
function pushDataToKhoj (regenerate = false) {
|
||||||
|
// Don't sync if token or hostURL is not set or if already syncing
|
||||||
|
if (store.get('khojToken') === '' || store.get('hostURL') === '' || store.get('syncing') === true) {
|
||||||
|
const win = BrowserWindow.getAllWindows()[0];
|
||||||
|
if (win) win.webContents.send('update-state', state);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
store.set('syncing', true);
|
||||||
|
}
|
||||||
|
|
||||||
let filesToPush = [];
|
let filesToPush = [];
|
||||||
const files = store.get('files') || [];
|
const files = store.get('files') || [];
|
||||||
const folders = store.get('folders') || [];
|
const folders = store.get('folders') || [];
|
||||||
@@ -192,11 +201,13 @@ function pushDataToKhoj (regenerate = false) {
|
|||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
// Syncing complete
|
// Syncing complete
|
||||||
|
store.set('syncing', false);
|
||||||
const win = BrowserWindow.getAllWindows()[0];
|
const win = BrowserWindow.getAllWindows()[0];
|
||||||
if (win) win.webContents.send('update-state', state);
|
if (win) win.webContents.send('update-state', state);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Syncing complete
|
// Syncing complete
|
||||||
|
store.set('syncing', false);
|
||||||
const win = BrowserWindow.getAllWindows()[0];
|
const win = BrowserWindow.getAllWindows()[0];
|
||||||
if (win) win.webContents.send('update-state', state);
|
if (win) win.webContents.send('update-state', state);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user