[feat] performace improvement stage 1

This commit is contained in:
kwaroran
2023-08-06 14:58:05 +09:00
parent 31763bb481
commit f3e96d8ba1
10 changed files with 180 additions and 106 deletions

View File

@@ -1,7 +1,7 @@
<script lang="ts">
import { DataBase, type loreBook } from "src/ts/storage/database";
import LoreBookData from "./LoreBookData.svelte";
import { selectedCharID } from "src/ts/stores";
import { CurrentChat, CurrentCharacter } from "src/ts/stores";
import Sortable from 'sortablejs/modular/sortable.core.esm.js';
import { onDestroy, onMount } from "svelte";
import { sleep } from "src/ts/util";
@@ -28,16 +28,16 @@
else if(submenu === 1){
let newLore:loreBook[] = []
idx.forEach((i) => {
newLore.push($DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore[i])
newLore.push($CurrentChat.localLore[i])
})
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore = newLore
$CurrentChat.localLore = newLore
}
else{
let newLore:loreBook[] = []
idx.forEach((i) => {
newLore.push($DataBase.characters[$selectedCharID].globalLore[i])
newLore.push($CurrentCharacter.globalLore[i])
})
$DataBase.characters[$selectedCharID].globalLore = newLore
$CurrentCharacter.globalLore = newLore
}
stb.destroy()
sorted += 1
@@ -86,26 +86,26 @@
{/each}
{/if}
{:else if submenu === 0}
{#if $DataBase.characters[$selectedCharID].globalLore.length === 0}
{#if $CurrentCharacter.globalLore.length === 0}
<span class="text-textcolor2">No Lorebook</span>
{:else}
{#each $DataBase.characters[$selectedCharID].globalLore as book, i}
<LoreBookData bind:value={$DataBase.characters[$selectedCharID].globalLore[i]} idx={i} onRemove={() => {
let lore = $DataBase.characters[$selectedCharID].globalLore
{#each $CurrentCharacter.globalLore as book, i}
<LoreBookData bind:value={$CurrentCharacter.globalLore[i]} idx={i} onRemove={() => {
let lore = $CurrentCharacter.globalLore
lore.splice(i, 1)
$DataBase.characters[$selectedCharID].globalLore = lore
$CurrentCharacter.globalLore = lore
}} onOpen={onOpen} onClose={onClose}/>
{/each}
{/if}
{:else if submenu === 1}
{#if $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore.length === 0}
{#if $CurrentChat.localLore.length === 0}
<span class="text-textcolor2">No Lorebook</span>
{:else}
{#each $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore as book, i}
<LoreBookData bind:value={$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore[i]} idx={i} onRemove={() => {
let lore = $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore
{#each $CurrentChat.localLore as book, i}
<LoreBookData bind:value={$CurrentChat.localLore[i]} idx={i} onRemove={() => {
let lore = $CurrentChat.localLore
lore.splice(i, 1)
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore = lore
$CurrentChat.localLore = lore
}} onOpen={onOpen} onClose={onClose}/>
{/each}
{/if}

View File

@@ -1,7 +1,7 @@
<script lang="ts">
import { DataBase } from "../../../ts/storage/database";
import { language } from "../../../lang";
import {selectedCharID} from '../../../ts/stores'
import {CurrentCharacter, selectedCharID} from '../../../ts/stores'
import { DownloadIcon, FolderUpIcon, ImportIcon, PlusIcon } from "lucide-svelte";
import { addLorebook, exportLoreBook, importLoreBook } from "../../../ts/process/lorebook";
import Check from "../../UI/GUI/CheckInput.svelte";
@@ -17,7 +17,7 @@
<button on:click={() => {
submenu = 0
}} class="p-2 flex-1" class:bg-selected={submenu === 0}>
<span>{$DataBase.characters[$selectedCharID].type === 'group' ? language.group : language.character}</span>
<span>{$CurrentCharacter.type === 'group' ? language.group : language.character}</span>
</button>
<button on:click={() => {
submenu = 1
@@ -33,32 +33,32 @@
{/if}
{#if submenu !== 2}
{#if !globalMode}
<span class="text-textcolor2 mt-2 mb-6 text-sm">{submenu === 0 ? $DataBase.characters[$selectedCharID].type === 'group' ? language.groupLoreInfo : language.globalLoreInfo : language.localLoreInfo}</span>
<span class="text-textcolor2 mt-2 mb-6 text-sm">{submenu === 0 ? $CurrentCharacter.type === 'group' ? language.groupLoreInfo : language.globalLoreInfo : language.localLoreInfo}</span>
{/if}
<LoreBookList bind:globalMode bind:submenu />
{:else}
{#if $DataBase.characters[$selectedCharID].loreSettings}
{#if $CurrentCharacter.loreSettings}
<div class="flex items-center mt-4">
<Check check={false} onChange={() => {
$DataBase.characters[$selectedCharID].loreSettings = undefined
$CurrentCharacter.loreSettings = undefined
}}
name={language.useGlobalSettings}
/>
</div>
<div class="flex items-center mt-4">
<Check bind:check={$DataBase.characters[$selectedCharID].loreSettings.recursiveScanning} name={language.recursiveScanning}/>
<Check bind:check={$CurrentCharacter.loreSettings.recursiveScanning} name={language.recursiveScanning}/>
</div>
<div class="flex items-center mt-4">
<Check bind:check={$DataBase.characters[$selectedCharID].loreSettings.fullWordMatching} name={language.fullWordMatching}/>
<Check bind:check={$CurrentCharacter.loreSettings.fullWordMatching} name={language.fullWordMatching}/>
</div>
<span class="text-textcolor mt-4 mb-2">{language.loreBookDepth}</span>
<NumberInput size="sm" min={0} max={20} bind:value={$DataBase.characters[$selectedCharID].loreSettings.scanDepth} />
<NumberInput size="sm" min={0} max={20} bind:value={$CurrentCharacter.loreSettings.scanDepth} />
<span class="text-textcolor">{language.loreBookToken}</span>
<NumberInput size="sm" min={0} max={4096} bind:value={$DataBase.characters[$selectedCharID].loreSettings.tokenBudget} />
<NumberInput size="sm" min={0} max={4096} bind:value={$CurrentCharacter.loreSettings.tokenBudget} />
{:else}
<div class="flex items-center mt-4">
<Check check={true} onChange={() => {
$DataBase.characters[$selectedCharID].loreSettings = {
$CurrentCharacter.loreSettings = {
tokenBudget: $DataBase.loreBookToken,
scanDepth:$DataBase.loreBookDepth,
recursiveScanning: false