Initially load option at newIndex and remaining options on focus

Optimization for big notetypes:
Should increase efficiency from O(n²) to O(n). Test on notetype with 500 templates shows significant improvement in load time (~10s down to ~1s).
This commit is contained in:
Matthias M 2021-11-15 12:02:17 +01:00
parent 9d1e131e7f
commit f42beee45c

View file

@ -21,29 +21,34 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
current = oldNames[newIndex] || tr.changeNotetypeNothing(); current = oldNames[newIndex] || tr.changeNotetypeNothing();
} }
function onChange(evt: Event) {
const oldIdx = parseInt((evt.target as HTMLSelectElement).value, 10);
state.setOldIndex(ctx, newIndex, oldIdx);
}
// optimization for big notetypes // optimization for big notetypes
let active: boolean = false; let active: boolean = false;
function activate(evt: Event) { function activate(evt: Event) {
active = true; active = true;
} }
function onChange(evt: Event) {
const oldIdx = parseInt((evt.target as HTMLSelectElement).value, 10);
state.setOldIndex(ctx, newIndex, oldIdx);
}
</script> </script>
<Row --cols={2}> <Row --cols={2}>
<Col --col-size={1}> <Col --col-size={1}>
<!-- svelte-ignore a11y-no-onchange --> <!-- svelte-ignore a11y-no-onchange -->
<select <select
value={$info.getOldIndex(ctx, newIndex)} value={active ? $info.getOldIndex(ctx, newIndex) : 0}
class="form-select" class="form-select"
on:focusin={activate}
on:change={onChange} on:change={onChange}
> >
{#each $info.getOldNamesIncludingNothing(ctx) as name, idx} {#if active}
{#each oldNames as name, idx}
<option value={idx}>{name}</option> <option value={idx}>{name}</option>
{/each} {/each}
{:else}
<option value={0}>{current}</option>
{/if}
</select> </select>
</Col> </Col>
<Col --col-size={1}> <Col --col-size={1}>