Skip to content

Commit 6bbd09c

Browse files
committed
feat: optimize sql execution and import workflows
1 parent 857494d commit 6bbd09c

36 files changed

Lines changed: 3013 additions & 1192 deletions

electron.vite.config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@ export default defineConfig({
1818
root: resolve('src/renderer'),
1919
build: {
2020
rollupOptions: {
21-
input: resolve('src/renderer/index.html')
21+
input: resolve('src/renderer/index.html'),
22+
output: {
23+
manualChunks(id) {
24+
if (!id.includes('node_modules')) return undefined
25+
if (id.includes('monaco-editor') || id.includes('@monaco-editor')) return 'vendor-monaco'
26+
if (id.includes('@ant-design/icons')) return 'vendor-icons'
27+
if (id.includes('react') || id.includes('scheduler')) return 'vendor-react'
28+
if (id.includes('zustand')) return 'vendor-state'
29+
if (id.includes('lodash') || id.includes('dayjs') || id.includes('xlsx')) return 'vendor-utils'
30+
return 'vendor'
31+
},
32+
},
2233
}
2334
},
2435
plugins: [react()],

src/main/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { IPC } from '../shared/types/ipc-channels'
55
import { registerAllIPC } from './ipc/index'
66
import * as connectionManager from './services/connection-manager'
77
import * as localStore from './services/local-store'
8+
import * as backupService from './services/backup'
89
import * as logger from './utils/logger'
910

1011
let mainWindow: BrowserWindow | null = null
@@ -152,6 +153,7 @@ app.whenReady().then(() => {
152153
logger.info('App starting...')
153154
localStore.init()
154155
connectionManager.initializeHeartbeatInterval()
156+
backupService.startScheduleRunner()
155157
registerAllIPC()
156158

157159
// Window control IPC
@@ -193,6 +195,7 @@ app.on('before-quit', async () => {
193195
logger.info('App quitting, cleaning up...')
194196
tray?.destroy()
195197
tray = null
198+
backupService.stopScheduleRunner()
196199
localStore.flushLocalStoreQueues()
197200
await connectionManager.disconnectAll()
198201
})

src/main/ipc/backup.ipc.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import { ipcMain } from 'electron'
22
import { IPC } from '../../shared/types/ipc-channels'
33
import * as backup from '../services/backup'
4-
import * as localStore from '../services/local-store'
54

65
export function registerBackupIPC() {
76
ipcMain.handle(IPC.BACKUP_CREATE, async (_e, config) => {
87
return backup.createBackup(config)
98
})
109

11-
ipcMain.handle(IPC.BACKUP_RESTORE, async (_e, connId: string, filePath: string) => {
12-
return backup.restoreBackup(connId, filePath)
10+
ipcMain.handle(IPC.BACKUP_RESTORE, async (_e, connId: string, filePath: string, options) => {
11+
return backup.restoreBackup(connId, filePath, options)
1312
})
1413

1514
ipcMain.handle(IPC.BACKUP_LIST, async (_e, connId: string) => {
1615
return backup.listBackups(connId)
1716
})
1817

19-
ipcMain.handle(IPC.BACKUP_SCHEDULE, async (_e, schedule) => {
20-
localStore.backupSchedules.save(schedule)
18+
ipcMain.handle(IPC.BACKUP_SCHEDULE, async (_e, request) => {
19+
return backup.handleScheduleRequest(request)
2120
})
2221
}

src/main/ipc/import-export.ipc.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type ExportDataOptions = {
1616
insertStyle?: 'single' | 'multi' | 'ignore' | 'replace'
1717
}
1818

19-
const IMPORT_EXTS = new Set(['.csv', '.tsv', '.xlsx', '.xls'])
19+
const IMPORT_EXTS = new Set(['.csv', '.tsv', '.xlsx', '.xls', '.sql', '.gz'])
2020
const EXPORT_EXTS = new Set(['.csv', '.json', '.sql', '.xlsx', '.xls'])
2121

2222
function validateFilePath(filePath: string, allowedExts: Set<string>): void {
@@ -36,6 +36,9 @@ export function registerImportExportIPC() {
3636
ipcMain.handle(IPC.IMPORT_FILE, async (_e, connId: string, db: string, table: string, filePath: string, options?: ImportOptions) => {
3737
validateFilePath(filePath, IMPORT_EXTS)
3838
const ext = path.extname(filePath).toLowerCase()
39+
if (ext === '.sql' || filePath.toLowerCase().endsWith('.sql.gz')) {
40+
return importExport.importSQL(connId, db, filePath, options)
41+
}
3942
if (ext === '.csv' || ext === '.tsv') {
4043
return importExport.importCSV(connId, db, table, filePath, options)
4144
}
@@ -44,6 +47,10 @@ export function registerImportExportIPC() {
4447

4548
ipcMain.handle(IPC.IMPORT_PREVIEW, async (_e, filePath: string) => {
4649
validateFilePath(filePath, IMPORT_EXTS)
50+
const lower = filePath.toLowerCase()
51+
if (lower.endsWith('.sql') || lower.endsWith('.sql.gz')) {
52+
return { columns: [], rows: [], totalRows: 0 }
53+
}
4754
return importExport.previewImport(filePath)
4855
})
4956

0 commit comments

Comments
 (0)