duplicator improvements

This commit is contained in:
Jan Prochazka 2023-02-16 17:25:54 +01:00
parent b514f8ae35
commit fb1c2c61fb
3 changed files with 65 additions and 6 deletions

View File

@ -91,6 +91,7 @@ class DuplicatorItemHolder {
let inserted = 0; let inserted = 0;
let mapped = 0; let mapped = 0;
let missing = 0; let missing = 0;
let lastLogged = new Date();
const writeStream = createAsyncWriteStream(this.duplicator.stream, { const writeStream = createAsyncWriteStream(this.duplicator.stream, {
processItem: async chunk => { processItem: async chunk => {
@ -146,6 +147,13 @@ class DuplicatorItemHolder {
break; break;
} }
} }
if (new Date().getTime() - lastLogged.getTime() > 5000) {
logger.info(
`Duplicating ${this.item.name} in progress, inserted ${inserted} rows, mapped ${mapped} rows, missing ${missing} rows`
);
lastLogged = new Date();
}
// this.idMap[oldId] = newId; // this.idMap[oldId] = newId;
}, },
}); });

View File

@ -129,7 +129,7 @@ export function editorAddColumn(table: TableInfo, column: EditorColumnInfo, addD
if (addDataCommand && column.defaultValue) { if (addDataCommand && column.defaultValue) {
defineDataCommand(res, () => ({ defineDataCommand(res, () => ({
type: 'setField', type: 'setField',
field: column.columnName, newField: column.columnName,
value: parseSqlDefaultValue(column.defaultValue), value: parseSqlDefaultValue(column.defaultValue),
})); }));
} }

View File

@ -12,6 +12,16 @@
testEnabled: () => getCurrentEditor()?.canRun(), testEnabled: () => getCurrentEditor()?.canRun(),
onClick: () => getCurrentEditor().run(), onClick: () => getCurrentEditor().run(),
}); });
registerCommand({
id: 'dataDuplicator.kill',
category: 'Data duplicator',
icon: 'icon close',
name: 'Kill',
toolbar: true,
isRelatedToTab: true,
testEnabled: () => getCurrentEditor()?.canKill(),
onClick: () => getCurrentEditor().kill(),
});
</script> </script>
<script lang="ts"> <script lang="ts">
@ -22,6 +32,7 @@
import ToolStripContainer from '../buttons/ToolStripContainer.svelte'; import ToolStripContainer from '../buttons/ToolStripContainer.svelte';
import invalidateCommands from '../commands/invalidateCommands'; import invalidateCommands from '../commands/invalidateCommands';
import registerCommand from '../commands/registerCommand'; import registerCommand from '../commands/registerCommand';
import Link from '../elements/Link.svelte';
import ObjectConfigurationControl from '../elements/ObjectConfigurationControl.svelte'; import ObjectConfigurationControl from '../elements/ObjectConfigurationControl.svelte';
import TableControl from '../elements/TableControl.svelte'; import TableControl from '../elements/TableControl.svelte';
import VerticalSplitter from '../elements/VerticalSplitter.svelte'; import VerticalSplitter from '../elements/VerticalSplitter.svelte';
@ -36,6 +47,7 @@
import createActivator, { getActiveComponent } from '../utility/createActivator'; import createActivator, { getActiveComponent } from '../utility/createActivator';
import { useArchiveFiles, useArchiveFolders, useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders'; import { useArchiveFiles, useArchiveFolders, useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
import useEffect from '../utility/useEffect'; import useEffect from '../utility/useEffect';
import useTimerLabel from '../utility/useTimerLabel';
export let conid; export let conid;
export let database; export let database;
@ -47,16 +59,20 @@
export const activator = createActivator('DataDuplicatorTab', true); export const activator = createActivator('DataDuplicatorTab', true);
const timerLabel = useTimerLabel();
$: connection = useConnectionInfo({ conid }); $: connection = useConnectionInfo({ conid });
$: dbinfo = useDatabaseInfo({ conid, database }); $: dbinfo = useDatabaseInfo({ conid, database });
$: archiveFolders = useArchiveFolders(); $: archiveFolders = useArchiveFolders();
$: archiveFiles = useArchiveFiles({ folder: $editorState?.value?.archiveFolder }); $: archiveFiles = useArchiveFiles({ folder: $editorState?.value?.archiveFolder });
$: pairedNames = _.intersectionBy( $: pairedNames = _.sortBy(
$dbinfo?.tables?.map(x => x.pureName), _.intersectionBy(
$archiveFiles?.map(x => x.name), $dbinfo?.tables?.map(x => x.pureName),
(x: string) => _.toUpper(x) $archiveFiles?.map(x => x.name),
(x: string) => _.toUpper(x)
)
); );
$: { $: {
@ -117,6 +133,7 @@
const resp = await apiCall('runners/start', { script }); const resp = await apiCall('runners/start', { script });
runid = resp.runid; runid = resp.runid;
runnerId = runid; runnerId = runid;
timerLabel.start();
} }
$: effect = useEffect(() => registerRunnerDone(runnerId)); $: effect = useEffect(() => registerRunnerDone(runnerId));
@ -138,6 +155,17 @@
busy = false; busy = false;
}; };
export function canKill() {
return busy;
}
export function kill() {
apiCall('runners/cancel', {
runid: runnerId,
});
timerLabel.stop();
}
// $: console.log('$archiveFiles', $archiveFiles); // $: console.log('$archiveFiles', $archiveFiles);
// $: console.log('$editorState', $editorState.value); // $: console.log('$editorState', $editorState.value);
@ -160,10 +188,26 @@
}); });
// $: console.log('$archiveFolders', $archiveFolders); // $: console.log('$archiveFolders', $archiveFolders);
const changeCheckStatus = isChecked => () => {
setEditorData(old => {
const tables = { ...old?.tables };
for (const table of pairedNames) {
tables[table] = {
...old?.tables?.[table],
isChecked,
};
}
return {
...old,
tables,
};
});
};
</script> </script>
<ToolStripContainer> <ToolStripContainer>
<VerticalSplitter> <VerticalSplitter initialValue="70%">
<svelte:fragment slot="1"> <svelte:fragment slot="1">
<div class="wrapper"> <div class="wrapper">
<ObjectConfigurationControl title="Configuration"> <ObjectConfigurationControl title="Configuration">
@ -185,6 +229,12 @@
</ObjectConfigurationControl> </ObjectConfigurationControl>
<ObjectConfigurationControl title="Imported files"> <ObjectConfigurationControl title="Imported files">
<div class="mb-2">
<Link onClick={changeCheckStatus(true)}>Check all</Link>
|
<Link onClick={changeCheckStatus(false)}>Uncheck all</Link>
</div>
<TableControl <TableControl
rows={tableRows} rows={tableRows}
columns={[ columns={[
@ -247,6 +297,7 @@
<svelte:fragment slot="toolstrip"> <svelte:fragment slot="toolstrip">
<ToolStripCommandButton command="dataDuplicator.run" /> <ToolStripCommandButton command="dataDuplicator.run" />
<ToolStripCommandButton command="dataDuplicator.kill" />
</svelte:fragment> </svelte:fragment>
</ToolStripContainer> </ToolStripContainer>